"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.fields = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const date_fns_1 = require("date-fns");
const zod_1 = __importDefault(require("zod"));
exports.fields = {
    healthiePatientId: {
        id: 'healthiePatientId',
        label: 'Healthie patient ID',
        description: 'The ID of the patient in Healthie',
        type: extensions_core_1.FieldType.STRING,
        required: true,
    },
    name: {
        id: 'name',
        label: 'Name',
        description: 'The name of the goal',
        type: extensions_core_1.FieldType.STRING,
        required: true,
    },
    titleLink: {
        id: 'titleLink',
        label: 'Title link',
        description: 'The link to add behind the goal',
        type: extensions_core_1.FieldType.TEXT,
        required: false,
    },
    repeat: {
        id: 'repeat',
        label: 'Repeat',
        description: `The frequency of this goal. Possible values are: Daily, Weekly, Once. Defaults to "Once"`,
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    dueDate: {
        id: 'dueDate',
        label: 'Due date',
        description: 'The date the goal should end and dissapear from the portal',
        type: extensions_core_1.FieldType.DATE,
        required: false,
    },
};
exports.FieldsValidationSchema = zod_1.default.object({
    healthiePatientId: zod_1.default.string().min(1),
    name: zod_1.default.string().min(1),
    titleLink: zod_1.default.string().optional(),
    repeat: zod_1.default
        .union([zod_1.default.enum(['Daily', 'Weekly', 'Once']), zod_1.default.literal('')])
        .optional()
        .default('Once')
        .transform((val) => (val === '' ? 'Once' : val)),
    dueDate: zod_1.default
        .union([zod_1.default.coerce.date(), zod_1.default.literal('')])
        .optional()
        .transform((date) => date !== undefined && date !== '' ? (0, date_fns_1.format)(date, 'yyyy-MM-dd') : undefined)
        .refine((dueDateString) => {
        if (dueDateString === undefined)
            return true;
        const today = new Date();
        const dueDate = new Date(dueDateString);
        return (0, date_fns_1.isAfter)(dueDate, today);
    }, {
        message: 'Due date must be at least 1 day in the future.',
    }),
});
//# sourceMappingURL=fields.js.map