"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.POPSession = void 0;
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("path"));
const Data_1 = require("../basetypes/Data");
const MessageHeader_1 = require("../smime/MessageHeader");
const POPMessageInfo_1 = require("./POPMessageInfo");
// 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 { POPSession: _POPSession } = bindings;
/**
 * POPSession Class
 *
 * @public
 */
class POPSession extends bindings.POPSession {
    constructor() {
        super();
        const handle = new _POPSession();
        this.handle = handle;
    }
    /**
     * Set hostname
     *
     * @memberof POPSession
     */
    set hostname(hostname) {
        this.handle.hostname = hostname;
    }
    /**
     * Get hostname
     *
     * @type {string}
     * @memberof POPSession
     */
    get hostname() {
        return this.handle.hostname;
    }
    /**
     * Set port
     *
     * @memberof POPSession
     */
    set port(port) {
        this.handle.port = port;
    }
    /**
     * Get port
     *
     * @type {number}
     * @memberof POPSession
     */
    get port() {
        return this.handle.port;
    }
    /**
     * Set string
     *
     * @memberof POPSession
     */
    set username(username) {
        this.handle.username = username;
    }
    /**
     * Get string
     *
     * @type {string}
     * @memberof POPSession
     */
    get username() {
        return this.handle.username;
    }
    /**
     * Set password
     *
     * @memberof POPSession
     */
    set password(password) {
        this.handle.password = password;
    }
    /**
     * Get password
     *
     * @type {string}
     * @memberof POPSession
     */
    get password() {
        return this.handle.password;
    }
    /**
     * Set checkCertificateEnabled
     *
     * @memberof POPSession
     */
    set checkCertificateEnabled(isEnabled) {
        this.handle.checkCertificateEnabled = isEnabled;
    }
    /**
     * Get checkCertificateEnabled
     *
     * @type {boolean}
     * @memberof POPSession
     */
    get checkCertificateEnabled() {
        return this.handle.checkCertificateEnabled;
    }
    /**
     * Set authType
     *
     * @memberof POPSession
     */
    set authType(authType) {
        this.handle.authType = authType;
    }
    /**
     * Get authType
     *
     * @type {AuthType}
     * @memberof POPSession
     */
    get authType() {
        return this.handle.authType;
    }
    /**
     * Set connectionType
     *
     * @memberof POPSession
     */
    set connectionType(connectionType) {
        this.handle.connectionType = connectionType;
    }
    /**
     * Get connectionType
     *
     * @type {ConnectionType}
     * @memberof POPSession
     */
    get connectionType() {
        return this.handle.connectionType;
    }
    /**
     * Set timeout
     *
     * @memberof POPSession
     */
    set timeout(timeoutValue) {
        this.handle.timeout = timeoutValue;
    }
    /**
     * Get timeout
     *
     * @type {number}
     * @memberof POPSession
     */
    get timeout() {
        return this.handle.timeout;
    }
    /**
     * 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
     *
     * @returns {number} 0 - success, other - failure
     *
     * @memberof POPSession
     */
    async checkAccount() {
        return this.handle.checkAccount();
    }
    /**
     * Connect
     *
     * @return {number} returns error code
     * @memberof POPSession
     */
    connect() {
        return this.handle.connect();
    }
    /**
     * Disconnect connection
     *
     * @memberof POPSession
     */
    disconnect() {
        this.handle.disconnect();
    }
    /**
     * Login if needed to session
     *
     * @return {*}  {number}
     * @memberof POPSession
     */
    login() {
        return this.handle.login();
    }
    /**
     * Fetch message info for all messages
     *
     * @return {*}  {POPMessageInfo[]} array of all messages info
     * @memberof POPSession
     */
    fetchMessages() {
        const msgsInfos = this.handle.fetchMessages();
        const result = [];
        for (let curInfo of msgsInfos) {
            const value = new POPMessageInfo_1.POPMessageInfo();
            value.handle = curInfo;
            result.push(value);
        }
        return result;
    }
    /**
     * Fetch message header by index or message info
     *
     * @param {number | POPMessageInfo} msg message index or info to fetch header
     * @return {*}  {MessageHeader}
     * @memberof POPSession
     */
    fetchHeader(msg) {
        const msgHdr = (typeof msg === "number")
            ? this.handle.fetchHeader(msg)
            : this.handle.fetchHeader(msg.handle);
        const value = new MessageHeader_1.MessageHeader();
        value.handle = msgHdr;
        return value;
    }
    /**
     * Fetch message data by index or info
     *
     * @param {number} index Index or info of message to fetch header
     * @return {*}  {Data}
     * @memberof POPSession
     */
    fetchMessage(msg) {
        const msgData = (typeof msg === "number")
            ? this.handle.fetchMessage(msg)
            : this.handle.fetchMessage(msg.handle);
        const value = new Data_1.Data();
        value.handle = msgData;
        return value;
    }
    /**
     * Delets message by index or message info
     *
     * @param {number} index Index or info of message to fetch header
     * @return {*}  {Data}
     * @memberof POPSession
     */
    deleteMessage(msg) {
        if ((typeof msg === "number")) {
            return this.handle.deleteMessage(msg);
        }
        return this.handle.deleteMessage(msg.handle);
    }
    /**
     * noop
     *
     * @return {*}  {number} error code
     * @memberof POPSession
     */
    noop() {
        return this.handle.noop();
    }
}
exports.POPSession = POPSession;
//# sourceMappingURL=POPSession.js.map