import { z } from "zod";

export const serviceSchema = z.object({
  customerId: z.string().min(1, "Müşteri seçin."),
  name: z.string().trim().min(1, "Hizmet adı zorunlu.").max(255),
  description: z
    .string()
    .trim()
    .max(2000)
    .optional()
    .transform((v) => (v ? v : undefined)),
  unitPrice: z
    .union([z.number(), z.string()])
    .transform((v) => (typeof v === "string" ? Number(v.replace(",", ".")) : v))
    .pipe(z.number().nonnegative("Negatif olamaz.")),
  recurring: z
    .union([z.boolean(), z.literal("on"), z.literal(""), z.undefined()])
    .transform((v) => v === true || v === "on")
    .optional(),
  currency: z.enum(["TRY", "USD", "EUR"]).optional().default("TRY"),
  billingPeriod: z.enum(["monthly", "yearly", "onetime"]).optional().default("onetime"),
  assigneeIds: z.array(z.string().min(1)).optional().default([]),
});

export type ServiceInput = z.infer<typeof serviceSchema>;
