"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteInbox = exports.createInbox = exports.mailSlurp = void 0;
const mailslurp_client_1 = require("mailslurp-client");
exports.mailSlurp = new mailslurp_client_1.MailSlurp({
    apiKey: process.env.MAIL_SLURP_API_KEY,
});
async function createInbox(emailAddress, expriesIn = 1200000) {
    try {
        const inbox = await exports.mailSlurp.createInbox(emailAddress, undefined, undefined, undefined, undefined, undefined, undefined, expriesIn);
        console.log(`Created inbox ${inbox.id}`);
        return inbox;
    }
    catch (error) {
        throw new Error('Failed to create inbox: ' + String(error));
    }
}
exports.createInbox = createInbox;
async function deleteInbox(id) {
    try {
        console.log(`Deleting inbox ${id}`);
        await exports.mailSlurp.deleteInbox(id);
    }
    catch (error) {
        if (error instanceof Error &&
            (error.message.includes('404') ||
                error.message.includes('does not exist'))) {
            console.log('Failed to create inbox, could be a timing issue on MailSlurp side: ' +
                String(error));
        }
        else {
            throw new Error('Failed to delete inbox: ' + String(error));
        }
    }
}
exports.deleteInbox = deleteInbox;
