"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.fields = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const zod_1 = require("zod");
const date_fns_1 = require("date-fns");
const graphql_1 = require("../../../gql/graphql");
const extensions_core_2 = require("@awell-health/extensions-core");
const getTimezones_1 = require("./getTimezones");
const SexEnum = zod_1.z.enum([graphql_1.Sex.Female, graphql_1.Sex.Male, graphql_1.Sex.NotKnown]);
exports.fields = {
    patientCode: {
        id: 'patientCode',
        label: 'Patient code',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    firstName: {
        id: 'firstName',
        label: 'First name',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    lastName: {
        id: 'lastName',
        label: 'Last name',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    email: {
        id: 'email',
        label: 'Email',
        type: extensions_core_1.FieldType.STRING,
        /**
         * I am purposely not using the `email` stringType yet.
         * More information here: https://awellhealth.atlassian.net/jira/polaris/projects/AH/ideas/view/548618?selectedIssue=AH-176&issueViewLayout=sidebar&issueViewSection=capture&focusedInsightId=3144292
         */
        // stringType: StringType.EMAIL,
        required: false,
    },
    birthDate: {
        id: 'birthDate',
        label: 'Birth date',
        type: extensions_core_1.FieldType.DATE,
        required: false,
    },
    mobilePhone: {
        id: 'mobilePhone',
        label: 'Mobile phone',
        type: extensions_core_1.FieldType.STRING,
        stringType: extensions_core_1.StringType.PHONE,
        required: false,
    },
    phone: {
        id: 'phone',
        label: 'Phone',
        type: extensions_core_1.FieldType.STRING,
        stringType: extensions_core_1.StringType.PHONE,
        required: false,
    },
    preferredLanguage: {
        id: 'preferredLanguage',
        label: 'Preferred language',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    sex: {
        id: 'sex',
        label: 'Sex',
        description: 'Sex code as defined by ISO standard IEC_5218',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        options: {
            dropdownOptions: Object.values(SexEnum.enum).map((sex) => ({
                label: sex,
                value: sex,
            })),
        },
    },
    city: {
        id: 'city',
        label: 'City',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    country: {
        id: 'country',
        label: 'Country',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    state: {
        id: 'state',
        label: 'State',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    street: {
        id: 'street',
        label: 'Street',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    zip: {
        id: 'zip',
        label: 'ZIP',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    nationalRegistryNumber: {
        id: 'nationalRegistryNumber',
        label: 'National registry number',
        type: extensions_core_1.FieldType.STRING,
        required: false,
    },
    patientTimzone: {
        id: 'patientTimzone',
        label: 'Patient timezone',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        options: {
            dropdownOptions: (0, getTimezones_1.getTimezoneOptions)(),
        },
    },
};
exports.FieldsValidationSchema = zod_1.z.object({
    patientCode: zod_1.z.optional(zod_1.z.string().trim().nonempty()),
    firstName: zod_1.z.optional(zod_1.z.string().trim()),
    lastName: zod_1.z.optional(zod_1.z.string().trim()),
    birthDate: zod_1.z.optional(zod_1.z.coerce.date().transform((date) => (0, date_fns_1.formatISO)(date))),
    email: zod_1.z.optional(zod_1.z.string().trim().email('Value passed is not an email address')),
    phone: extensions_core_2.E164PhoneValidationOptionalSchema,
    mobilePhone: extensions_core_2.E164PhoneValidationOptionalSchema,
    street: zod_1.z.optional(zod_1.z.string().trim()),
    state: zod_1.z.optional(zod_1.z.string().trim()),
    country: zod_1.z.optional(zod_1.z.string().trim()),
    city: zod_1.z.optional(zod_1.z.string().trim()),
    zip: zod_1.z.optional(zod_1.z.string().trim()),
    preferredLanguage: zod_1.z.optional(zod_1.z.string().trim()),
    sex: zod_1.z.optional(zod_1.z.preprocess((v) => String(v).toUpperCase(), SexEnum)),
    nationalRegistryNumber: zod_1.z.string().trim().optional(),
    patientTimzone: zod_1.z.optional(zod_1.z
        .string()
        .trim()
        .refine((tz) => {
        try {
            return (Intl.DateTimeFormat(undefined, { timeZone: tz }).resolvedOptions()
                .timeZone === tz);
        }
        catch (_a) {
            return false;
        }
    }, 'Invalid timezone. Must be a valid IANA timezone format')),
});
//# sourceMappingURL=fields.js.map