import { z } from "zod";

export const profitShareSchemeInputSchema = z
  .object({
    code: z.string().trim().max(20).optional().or(z.literal("")),
    name: z.string().trim().min(1, "Nama skema wajib diisi").max(150),
    share_agent: z.coerce.number().min(0, "Share agen minimal 0").max(100, "Share agen maksimal 100"),
    share_company: z.coerce.number().min(0, "Share perusahaan minimal 0").max(100, "Share perusahaan maksimal 100"),
    status: z.enum(["ACTIVE", "INACTIVE"]).default("ACTIVE")
  })
  .superRefine((data, ctx) => {
    const total = Number((data.share_agent + data.share_company).toFixed(2));
    if (total !== 100) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: "Total share agen dan share perusahaan harus 100%",
        path: ["share_agent"]
      });
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: "Total share agen dan share perusahaan harus 100%",
        path: ["share_company"]
      });
    }
  });
