import { z } from "zod";

const PROSTHETIC_TYPES = [
  "metal_porselen",
  "zirkonyum",
  "implant_ustu_zirkonyum",
  "gecici",
  "e_max",
  "diger",
] as const;

export const prostheticSchema = z.object({
  name: z.string().trim().min(1, "Ürün adı zorunlu.").max(255),
  type: z.enum(PROSTHETIC_TYPES, { message: "Protez türü seçin." }),
  unitPrice: z
    .union([z.string(), z.number()])
    .transform((v) => {
      if (typeof v === "number") return v;
      const n = Number(v.replace(",", "."));
      return Number.isFinite(n) ? n : NaN;
    })
    .pipe(z.number().min(0, "Negatif olamaz.")),
  currency: z
    .string()
    .trim()
    .max(8)
    .optional()
    .transform((v) => (v ? v.toUpperCase() : "TRY")),
});

export type ProstheticInput = z.infer<typeof prostheticSchema>;
