"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const mablscript_step_types_1 = require("../../mablscript-step-types");
const DownloadStep_1 = require("@mablhq/test-model/steps/DownloadStep");
const DownloadBaseStep_1 = __importStar(require("./DownloadBaseStep"));
class DownloadStep extends DownloadBaseStep_1.default {
    static getStepType() {
        return mablscript_step_types_1.StepType.DOWNLOAD;
    }
    constructor(values) {
        super({
            stepType: DownloadStep.getStepType(),
            awaitSymbol: 'await_download',
            ...values,
        });
    }
    static create(descriptor) {
        const step = new DownloadStep(descriptor);
        step.generateStepId();
        return step;
    }
    static generateStepFromMablStep(mablDownloadStep) {
        const awaitParameters = {};
        const assertions = this.assertionsTemplate();
        Object.entries(mablDownloadStep.descriptor).forEach(([assertKey, expectedValue]) => {
            const snakeCasePropertyName = (0, DownloadBaseStep_1.toSnakeCasePropertyName)(assertKey);
            const matchedAssertionValueIndex = assertions.findIndex((assertion) => assertion.name === snakeCasePropertyName);
            if (matchedAssertionValueIndex >= 0) {
                assertions[matchedAssertionValueIndex].expected = expectedValue;
            }
        });
        const detectedProperties = DownloadStep_1.DownloadStep.populateDownloadArgsFromDescriptor(mablDownloadStep.descriptor);
        if (mablDownloadStep.descriptor.detected) {
            if (mablDownloadStep.descriptor.detected.file_mime_type) {
                detectedProperties.file_mime_type =
                    mablDownloadStep.descriptor.detected.file_mime_type;
            }
            if (mablDownloadStep.descriptor.detected.file_name) {
                detectedProperties.file_name =
                    mablDownloadStep.descriptor.detected.file_name;
            }
            if (mablDownloadStep.descriptor.detected.file_size_bytes !== undefined) {
                detectedProperties.file_size_bytes =
                    mablDownloadStep.descriptor.detected.file_size_bytes;
            }
        }
        return new DownloadStep({
            detectedProperties,
            assertions,
            awaitParameters,
            aiPrompt: mablDownloadStep.descriptor.aiPrompt,
            fileNameMatchMode: mablDownloadStep.descriptor.fileNameMatchMode,
        });
    }
}
exports.default = DownloadStep;
