"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.humanizeRemoveCookieStep = humanizeRemoveCookieStep;
exports.removeCookieStepToAIString = removeCookieStepToAIString;
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
const mablscript_step_types_1 = require("../../mablscript-step-types");
const type_utils_1 = require("../../type-utils");
const variable_names_util_1 = require("../../variable-names-util");
const BaseStep_1 = __importDefault(require("./BaseStep"));
const yaml_utils_1 = require("../yaml-utils");
class RemoveCookieStep extends BaseStep_1.default {
    static getStepType() {
        return mablscript_step_types_1.StepType.REMOVE_COOKIE;
    }
    constructor(cookie) {
        super(RemoveCookieStep.getStepType());
        this.cookie = cookie;
        this.options = {
            editable: true,
            executionContext: 'background',
        };
    }
    generateMablscript() {
        return `remove_cookie({ name : "${(0, mablscriptFind_1.escapeMablscriptString)(this.cookie.name)}" })`;
    }
    inputVariables() {
        const pattern = this.cookie?.name ?? '';
        return (0, type_utils_1.distinct)((0, variable_names_util_1.extractVariableNamesFromPattern)(pattern));
    }
    static generateStepFromMablStep(mablRemoveCookieStep) {
        return new RemoveCookieStep({ name: mablRemoveCookieStep.cookieName });
    }
    static create(descriptor) {
        const step = new RemoveCookieStep({ name: descriptor.name });
        step.generateStepId();
        return step;
    }
}
exports.default = RemoveCookieStep;
function humanizeRemoveCookieStep(step) {
    if (step.cookie) {
        return `Remove cookie with name "${step.cookie.name}"`;
    }
    throw new Error('Invalid step; humanized description cannot be generated.');
}
function removeCookieStepToAIString(step) {
    return (0, yaml_utils_1.toYaml)({
        stepType: step.stepType,
        name: step.cookie.name,
    });
}
