import { z } from "zod";

export const leadSchema = z.object({
  name: z.string().trim().min(1, "Lead adı zorunlu.").max(255),
  contactName: z.string().trim().max(255).optional().transform((v) => v || undefined),
  email: z.string().trim().email("Geçerli e-posta girin.").optional().or(z.literal("")).transform((v) => v || undefined),
  phone: z.string().trim().max(50).optional().transform((v) => v || undefined),
  source: z.enum(["website", "social", "referral", "cold_call", "event", "other"]).optional().default("other"),
  status: z.enum(["cold", "warm", "hot", "converted", "lost"]).optional().default("cold"),
  estimatedValue: z
    .union([z.number(), z.string()])
    .transform((v) => (typeof v === "string" ? (v === "" ? undefined : Number(v.replace(",", "."))) : v))
    .pipe(z.number().nonnegative().optional()),
  currency: z.enum(["TRY", "USD", "EUR"]).optional().default("TRY"),
  notes: z.string().trim().optional().transform((v) => v || undefined),
  assigneeId: z.string().optional().transform((v) => v || undefined),
});

export type LeadInput = z.infer<typeof leadSchema>;
