"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.ResponsesValidationSchema = exports.JsonStringValidationSchema = exports.fields = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const statusEnum = zod_1.z.enum(['ACCEPTED', 'PENDING', 'CANCELLED', 'REJECTED']);
exports.fields = {
    eventTypeId: {
        label: 'Event Type ID',
        id: 'eventTypeId',
        type: extensions_core_1.FieldType.NUMERIC,
        required: true,
        description: 'ID of the event type to book',
    },
    start: {
        label: 'Start',
        id: 'start',
        // STRING because it needs new DATE_TIME type
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: "Start time of the Event in ISO 8601 format, e.g. 2023-05-24T13:00:00.000Z. Please note that start/end time must be within user's availability hours.",
    },
    end: {
        label: 'End',
        id: 'end',
        // STRING because it needs new DATE_TIME type
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: "End time of the Event in ISO 8601 format, e.g. 2023-05-24T13:00:00.000Z. Please note that start/end time must be within user's availability hours.",
    },
    responses: {
        label: 'Responses',
        id: 'responses',
        type: extensions_core_1.FieldType.JSON,
        required: true,
        description: 'Object containing email, name, location',
    },
    metadata: {
        label: 'Metadata',
        id: 'metadata',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'Any metadata associated with the booking',
    },
    timeZone: {
        label: 'Timezone',
        id: 'timeZone',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: 'Timezone of the Attendee',
    },
    language: {
        label: 'Language',
        id: 'language',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: 'Language of the Attendee',
    },
    title: {
        label: 'Title',
        id: 'title',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'Title of Booking event',
    },
    recurringEventId: {
        label: 'Recurring Event Type ID',
        id: 'recurringEventId',
        type: extensions_core_1.FieldType.NUMERIC,
        required: false,
        description: 'Recurring event ID if the event is recurring',
    },
    description: {
        label: 'Description',
        id: 'description',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'Description of the meeting',
    },
    status: {
        label: 'Status',
        id: 'status',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'Status of the meeting to be set. Possible values: "ACCEPTED", "PENDING", "CANCELLED", "REJECTED".',
        options: {
            dropdownOptions: Object.values(statusEnum.enum).map((status) => ({
                label: status,
                value: status,
            })),
        },
    },
};
exports.JsonStringValidationSchema = zod_1.z
    .string()
    .transform((str, ctx) => {
    if ((0, lodash_1.isNil)(str) || (0, lodash_1.isEmpty)(str)) {
        return {};
    }
    try {
        const parsedJson = JSON.parse(str);
        if ((0, lodash_1.isEmpty)(parsedJson)) {
            return {};
        }
        if (typeof parsedJson !== 'object' || Array.isArray(parsedJson)) {
            ctx.addIssue({
                code: 'custom',
                message: 'The value should represent an object',
            });
            return zod_1.z.NEVER;
        }
        return parsedJson;
    }
    catch (e) {
        ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
        return zod_1.z.NEVER;
    }
});
exports.ResponsesValidationSchema = exports.JsonStringValidationSchema.transform((value, ctx) => {
    if ((0, lodash_1.isEmpty)(value)) {
        ctx.addIssue({
            code: 'custom',
            message: 'The value should represent a correct object',
        });
        return zod_1.z.NEVER;
    }
    return value;
});
exports.FieldsValidationSchema = zod_1.z.object({
    eventTypeId: extensions_core_1.NumericIdSchema,
    start: extensions_core_1.DateTimeSchema,
    end: extensions_core_1.DateTimeOptionalSchema,
    responses: exports.ResponsesValidationSchema,
    metadata: (0, extensions_core_1.makeStringOptional)(exports.JsonStringValidationSchema),
    timeZone: zod_1.z.string(),
    language: zod_1.z.string(),
    title: (0, extensions_core_1.makeStringOptional)(zod_1.z.string()),
    recurringEventId: (0, extensions_core_1.makeStringOptional)(extensions_core_1.NumericIdSchema),
    description: (0, extensions_core_1.makeStringOptional)(zod_1.z.string()),
    status: (0, extensions_core_1.makeStringOptional)(statusEnum),
});
//# sourceMappingURL=fields.js.map