"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoveCookieStep = void 0;
const MablStepV2_1 = require("../MablStepV2");
const MablAction_1 = require("../MablAction");
const CookieUtils_1 = require("./CookieUtils");
const mablscriptFind_1 = require("../mablscriptFind");
class RemoveCookieStep extends MablStepV2_1.MablStepV2 {
    static stepName = 'RemoveCookie';
    static actionCode = 'remove_cookie';
    static mablScriptStepNames = [RemoveCookieStep.actionCode];
    static yamlMablScriptNames = [RemoveCookieStep.stepName];
    cookieName;
    constructor(descriptor) {
        super(RemoveCookieStep.stepName, descriptor, RemoveCookieStep.actionCode);
        if (!this.isValidDescriptor(this.descriptor)) {
            throw new Error(`${RemoveCookieStep.stepName}: descriptor.name must be a string`);
        }
        this.cookieName = this.descriptor.name;
    }
    isValidDescriptor(value) {
        return typeof value.name === 'string';
    }
    getStepName() {
        return RemoveCookieStep.stepName;
    }
    static fromYaml(_stepName, stepArgs) {
        return new RemoveCookieStep(stepArgs);
    }
    static fromLegacyMablscript(args, _actions) {
        const stepDescriptor = {
            actionCode: RemoveCookieStep.actionCode,
            name: CookieUtils_1.CookieUtils.normalizeName(args[0].name),
        };
        const step = new RemoveCookieStep(stepDescriptor);
        step.actions = _actions;
        return step;
    }
    toMablscript() {
        return `remove_cookie({ name : "${(0, mablscriptFind_1.escapeMablscriptString)(this.cookieName)}" })`;
    }
    getInputVariables() {
        return MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.cookieName);
    }
    stepDescription() {
        return `Remove cookie: "${this.cookieName}"`;
    }
    static create(descriptor) {
        descriptor.id = descriptor.id ?? MablStepV2_1.MablStepV2.generateStepId();
        return new RemoveCookieStep(descriptor);
    }
}
exports.RemoveCookieStep = RemoveCookieStep;
