"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SMTPAsyncSession = void 0;
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("path"));
const DsnNotify_1 = require("../enums/DsnNotify");
// tslint:disable-next-line: no-var-requires
let bindings;
try {
    bindings = require(path.join(__dirname, "../../lib/binding/trusted_mailcore2.node"));
}
catch (e) {
    bindings = require(path.join(__dirname, "../../lib/binding/trusted_mailcore2_no_crypto.node"));
}
// tslint:disable-next-line
const { ISMTPAsyncSession: _ISMTPAsyncSession } = bindings;
/**
 * ISMTPAsyncSession Class
 *
 * @public
 */
class SMTPAsyncSession extends bindings.ISMTPAsyncSession {
    constructor() {
        super();
        const handle = new _ISMTPAsyncSession();
        this.handle = handle;
    }
    /**
     * Set hostname
     *
     * @memberof SMTPAsyncSession
     */
    set hostname(hostname) {
        this.handle.hostname = hostname;
    }
    /**
     * Get hostname
     *
     * @type {string}
     * @memberof SMTPAsyncSession
     */
    get hostname() {
        return this.handle.hostname;
    }
    /**
     * Set port
     *
     * @memberof SMTPAsyncSession
     */
    set port(port) {
        this.handle.port = port;
    }
    /**
     * Get port
     *
     * @type {number}
     * @memberof SMTPAsyncSession
     */
    get port() {
        return this.handle.port;
    }
    /**
     * Set string
     *
     * @memberof SMTPAsyncSession
     */
    set username(username) {
        this.handle.username = username;
    }
    /**
     * Get string
     *
     * @type {string}
     * @memberof SMTPAsyncSession
     */
    get username() {
        return this.handle.username;
    }
    /**
     * Set password
     *
     * @memberof SMTPAsyncSession
     */
    set password(password) {
        this.handle.password = password;
    }
    /**
     * Get password
     *
     * @type {string}
     * @memberof SMTPAsyncSession
     */
    get password() {
        return this.handle.password;
    }
    /**
     * Set checkCertificateEnabled
     *
     * @memberof SMTPAsyncSession
     */
    set checkCertificateEnabled(isEnabled) {
        this.handle.checkCertificateEnabled = isEnabled;
    }
    /**
     * Get checkCertificateEnabled
     *
     * @type {boolean}
     * @memberof SMTPAsyncSession
     */
    get checkCertificateEnabled() {
        return this.handle.checkCertificateEnabled;
    }
    /**
     * Set OAuth2Token
     *
     * @memberof SMTPAsyncSession
     */
    set OAuth2Token(OAuth2Token) {
        this.handle.OAuth2Token = OAuth2Token;
    }
    /**
     * Get OAuth2Token
     *
     * @type {string}
     * @memberof SMTPAsyncSession
     */
    get OAuth2Token() {
        return this.handle.OAuth2Token;
    }
    /**
     * Set authType
     *
     * @memberof SMTPAsyncSession
     */
    set authType(authType) {
        this.handle.authType = authType;
    }
    /**
     * Get authType
     *
     * @type {AuthType}
     * @memberof SMTPAsyncSession
     */
    get authType() {
        return this.handle.authType;
    }
    /**
     * Set connectionType
     *
     * @memberof SMTPAsyncSession
     */
    set connectionType(connectionType) {
        this.handle.connectionType = connectionType;
    }
    /**
     * Get connectionType
     *
     * @type {ConnectionType}
     * @memberof SMTPAsyncSession
     */
    get connectionType() {
        return this.handle.connectionType;
    }
    /**
     * Set strictGost flag (to force using GOST for TLS)
     *
     * @memberof IMAPSession
     */
    set strictGost(value) {
        this.handle.strictGost = value;
    }
    /**
     * Get strictGost flag (to force using GOST for TLS)
     *
     * @type {Boolean}
     * @memberof IMAPSession
     */
    get strictGost() {
        return this.handle.strictGost;
    }
    /**
     * Validate exist account
     *
     * @param {string} from address
     * @returns {number} 0 - success, other - failure
     *
     * @memberof SMTPAsyncSession
     */
    async checkAccount(from) {
        return this.handle.checkAccount(from);
    }
    /**
     * Send message to smtp server
     *
     * @param {string | Buffer} message message
     * @returns {number} error code. 0 - success, other - failure
     *
     * @memberof SMTPAsyncSession
     */
    async sendMessage(message, from, recipients) {
        return this.handle.sendMessage(message, from, recipients);
    }
    /**
     * Send message to smtp server
     *
     * @param {string} from address
     * @param {string[]} recipients recipients
     * @param {string | Buffer} message message body
     * @param {*} [notify=DsnNotify.DsnNotifyNone] DSN_NOTIFY. Default disabled
     * @returns {number} error code. 0 - success, other - failure
     *
     * @memberof SMTPAsyncSession
     */
    async sendMessageOperation(from, recipients, message, notify = DsnNotify_1.DsnNotify.DsnNotifyNone) {
        return new Promise((resolve, reject) => {
            this.handle.sendMessageOperation(from, recipients, message, notify, (error, result) => {
                if (error) {
                    reject(error);
                }
                resolve(result);
            });
        });
    }
    /**
     * Disconnect connection
     *
     * @memberof SMTPAsyncSession
     */
    disconnect() {
        this.handle.disconnect();
    }
    /**
     * Validate connection status
     *
     * @returns {boolean}
     *
     * @memberof SMTPAsyncSession
     */
    isDisconnected() {
        return this.handle.isDisconnected();
    }
}
exports.SMTPAsyncSession = SMTPAsyncSession;
//# sourceMappingURL=SMTPAsyncSession.js.map