"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsSchema = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const zod_1 = require("zod");
const periodEnum = zod_1.z.enum(['AM', 'PM']);
const frequencyEnum = zod_1.z.enum(['Daily', 'Weekly', 'Monthly']);
const weekdayEnum = zod_1.z.enum([
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday',
]);
// healthie doesn't validate correct form and can lead to errors - validation on our side
const monthdayEnum = zod_1.z.enum([
    '1st',
    '2nd',
    '3rd',
    '4th',
    '5th',
    '6th',
    '7th',
    '8th',
    '9th',
    '10th',
    '11th',
    '12th',
    '13th',
    '14th',
    '15th',
    '16th',
    '17th',
    '18th',
    '19th',
    '20th',
    '21st',
    '22nd',
    '23rd',
    '24th',
    '25th',
    '26th',
    '27th',
    '28th',
    '29th',
    '30th',
    '31st',
]);
const recurringSchema = zod_1.z.discriminatedUnion('frequency', [
    /**
     * If `frequency` is "daily"
     * then "period", "hour" and "minute" are required
     */
    zod_1.z.object({
        frequency: zod_1.z.literal(frequencyEnum.enum.Daily),
        hour: zod_1.z.coerce.number().min(1).max(12).transform(String),
        minute: zod_1.z.coerce.number().min(0).max(59).transform(String),
        period: periodEnum,
    }),
    /**
     * If `frequency` is "weekly"
     * then "weekday" is required
     */
    zod_1.z.object({
        frequency: zod_1.z.literal(frequencyEnum.enum.Weekly),
        weekday: weekdayEnum,
    }),
    /**
     * If `frequency` is "monthly"
     * then "monthday" is required
     */
    zod_1.z.object({
        frequency: zod_1.z.literal(frequencyEnum.enum.Monthly),
        monthday: monthdayEnum,
    }),
]);
exports.FieldsSchema = zod_1.z
    .object({
    healthie_patient_id: zod_1.z.string().nonempty(),
    form_id: zod_1.z.string().nonempty(),
    is_recurring: zod_1.z.boolean().optional(),
    frequency: zod_1.z.string().transform(lodash_1.capitalize).optional(),
    period: (0, extensions_core_1.makeStringOptional)(zod_1.z.string().toUpperCase()),
    minute: (0, extensions_core_1.makeStringOptional)(zod_1.z.coerce.string()),
    hour: (0, extensions_core_1.makeStringOptional)(zod_1.z.coerce.string()),
    weekday: (0, extensions_core_1.makeStringOptional)(zod_1.z.string().transform(lodash_1.capitalize)),
    monthday: (0, extensions_core_1.makeStringOptional)(zod_1.z.string().toLowerCase()),
    ends_on: extensions_core_1.DateOnlyOptionalSchema,
})
    .superRefine(({ healthie_patient_id, form_id, is_recurring, frequency, monthday, weekday, hour, minute, period, ends_on, }, ctx) => {
    // if is recurring, then check
    if (is_recurring === true) {
        recurringSchema.parse({
            frequency,
            hour,
            minute,
            period,
            weekday,
            monthday,
        });
    }
});
//# sourceMappingURL=sendFormCompletionRequest.zod.js.map