"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updatePatientSchema = exports.insertPatientSchema = exports.patientStatusOptions = exports.insuranceIdSchema = void 0;
const usedSchemas_1 = require("@repo/db/usedSchemas");
const zod_1 = require("zod");
const utils_1 = require("../utils");
exports.insuranceIdSchema = zod_1.z.preprocess((val) => {
    if (val === undefined || val === null)
        return undefined;
    // Accept numbers and strings
    if (typeof val === "number") {
        return String(val).replace(/\s+/g, "");
    }
    if (typeof val === "string") {
        const cleaned = val.replace(/\s+/g, "");
        if (cleaned === "")
            return undefined;
        return cleaned;
    }
    return val;
}, 
// After preprocess, require digits-only string (or optional nullable)
zod_1.z
    .string()
    .regex(/^[A-Za-z0-9]+$/, { message: "Insurance ID must contain only letters and digits" })
    .min(1)
    .max(32)
    .optional()
    .nullable());
// enum → select options
exports.patientStatusOptions = (0, utils_1.makeEnumOptions)(usedSchemas_1.PatientStatusSchema);
exports.insertPatientSchema = usedSchemas_1.PatientUncheckedCreateInputObjectSchema
    .omit({
    id: true,
    createdAt: true,
})
    .extend({
    insuranceId: exports.insuranceIdSchema, // enforce numeric insuranceId
});
exports.updatePatientSchema = usedSchemas_1.PatientUncheckedCreateInputObjectSchema
    .omit({
    id: true,
    createdAt: true,
    userId: true,
})
    .partial()
    .extend({
    insuranceId: exports.insuranceIdSchema, // enforce numeric insuranceId
});
