"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchClose = exports.closeBatch = void 0;
const SDK_1 = require("./SDK");
const utils = __importStar(require("@applitools/utils"));
function closeBatch(sdk) {
    return function closeBatch(settings) {
        utils.guard.notNull(settings.batchIds, { name: 'options.batchIds' });
        const { core } = (0, SDK_1.initSDK)(sdk);
        return core.closeBatch({
            settings: settings.batchIds.map(batchId => ({ batchId, eyesServerUrl: settings.serverUrl, ...settings })),
        });
    };
}
exports.closeBatch = closeBatch;
class BatchClose {
    get _sdk() {
        return this.constructor._sdk;
    }
    static async close(settings) {
        utils.guard.notNull(settings.batchIds, { name: 'options.batchIds' });
        const { core } = (0, SDK_1.initSDK)(this._sdk);
        await core.closeBatch({
            settings: settings.batchIds.map(batchId => ({ batchId, eyesServerUrl: settings.serverUrl, ...settings })),
        });
    }
    constructor(options) {
        this._settings = {};
        const { core } = (0, SDK_1.initSDK)(this._sdk);
        this._core = core;
        if (options)
            this._settings = options;
    }
    async close() {
        utils.guard.notNull(this._settings.batchIds, { name: 'batchIds' });
        await this._core.closeBatch({
            settings: this._settings.batchIds.map(batchId => ({
                batchId,
                eyesServerUrl: this._settings.serverUrl,
                ...this._settings,
            })),
        });
    }
    setBatchIds(batchIds) {
        this._settings.batchIds = batchIds;
        return this;
    }
    setUrl(serverUrl) {
        this._settings.serverUrl = serverUrl;
        return this;
    }
    setApiKey(apiKey) {
        this._settings.apiKey = apiKey;
        return this;
    }
    setProxy(proxy) {
        this._settings.proxy = proxy;
        return this;
    }
}
exports.BatchClose = BatchClose;
