"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateFlowExecutionSchema = void 0;
const zod_1 = __importDefault(require("zod"));
const fields_1 = require("./fields");
const lodash_1 = require("lodash");
const settings_1 = require("../../../../settings");
exports.CreateFlowExecutionSchema = zod_1.default
    .object({
    settings: settings_1.SettingsValidationSchema,
    fields: fields_1.FieldsValidationSchema,
})
    .superRefine((value, ctx) => {
    // if both `from` values missing - throw error
    if ((0, lodash_1.isNil)(value.settings.fromNumber) && (0, lodash_1.isNil)(value.fields.from)) {
        ctx.addIssue({
            code: zod_1.default.ZodIssueCode.custom,
            fatal: true,
            message: '"From" number is missing in both settings and in the action field.',
        });
    }
})
    .transform((val) => {
    var _a;
    return {
        settings: val.settings,
        fields: {
            ...val.fields,
            parameters: JSON.parse(val.fields.parameters),
            from: (_a = val.fields.from) !== null && _a !== void 0 ? _a : val.settings.fromNumber,
        },
    };
})
    .refine((v) => !(0, lodash_1.isNil)(v.fields.from) && typeof v.fields.from === 'string');
//# sourceMappingURL=actionSchema.js.map