"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) {
    if (!id) {
        return;
    }
    try {
        console.log(`Deleting inbox ${id}`);
        await Promise.race([
            exports.mailSlurp.deleteInbox(id),
            new Promise((_, reject) => setTimeout(() => reject(new Error('deleteInbox timeout exceeded')), 20000)),
        ]);
    }
    catch (error) {
        // Cleanup should be best-effort and must not fail the test flow.
        console.warn('Failed to delete inbox: ' + String(error));
    }
}
exports.deleteInbox = deleteInbox;
