import { MessageFlag } from "../enums/MessageFlag";
import * as path from "path";
import { IMAPMessageNativeBinding } from "../types";
import { NodeTrustedMailcore2NativeBinding } from "../types/NodeTrustedMailcore2NativeBinding";

// tslint:disable-next-line: no-var-requires
let bindings: NodeTrustedMailcore2NativeBinding;
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 { IMAPMessage: _IMAPMessage } = bindings;

/**
 * IMAPMessage Class
 *
 * @public
 */
class IMAPMessage extends bindings.IMAPMessage {
    public handle: IMAPMessageNativeBinding;

    constructor() {
        super();

        const handle = new _IMAPMessage();
        this.handle = handle;
    }

    /**
     * Get sequenceNumber
     *
     * @type {number}
     * @memberof IMAPMessage
     */
    get sequenceNumber(): number {
        return this.handle.sequenceNumber;
    }

    /**
     * Set sequenceNumber
     *
     * @memberof IMAPMessage
     */
    set sequenceNumber(sequenceNumberV: number) {
        this.handle.sequenceNumber = sequenceNumberV;
    }

    /**
     * Get uid
     *
     * @type {number}
     * @memberof IMAPMessage
     */
    get uid(): number {
        return this.handle.uid;
    }

    /**
     * Set uid
     *
     * @memberof IMAPMessage
     */
    set uid(uidV: number) {
        this.handle.uid = uidV;
    }

    /**
     * Get size
     *
     * @type {number}
     * @memberof IMAPMessage
     */
    get size(): number {
        return this.handle.size;
    }

    /**
     * Set size
     *
     * @memberof IMAPMessage
     */
    set size(sizeV: number) {
        this.handle.size = sizeV;
    }

    /**
     * Message flags
     *
     * @type {MessageFlag}
     * @memberof IMAPMessage
     */
    get flags(): MessageFlag {
        return this.handle.flags;
    }

    /**
     * Set message flags
     *
     * @memberof IMAPMessage
     */
    set flags(flags: MessageFlag) {
        this.handle.flags = flags;
    }

    /**
     * Original message flags
     *
     * @type {MessageFlag}
     * @memberof IMAPMessage
     */
    get originalFlags(): MessageFlag {
        return this.handle.originalFlags;
    }

    /**
     * Set original message flags
     *
     * @memberof IMAPMessage
     */
    set originalFlags(flags: MessageFlag) {
        this.handle.originalFlags = flags;
    }

    public htmlRendering(folder: string): string {
        return this.handle.htmlRendering(folder);
    }

    public description(): string {
        return this.handle.description();
    }
}

export { IMAPMessage };
