import * as z from "zod";

// ─── Commission Rate Schema ──────────────────────────────────────────────────

/**
 * Platform commission rate, as a percentage.
 *
 * Kept as a string in the form (the control is a text input) and coerced on
 * submit. Bounds mirror the backend DTO exactly: `@Min(0) @Max(100)`.
 * Messages are dictionary keys — resolved through `t()` by FormField.
 */
export const commissionRateSchema = z.object({
  customCommissionRate: z
    .string()
    .min(1, { message: "providers.validation.commissionRequired" })
    .refine(
      (value) => {
        const parsed = Number(value);
        return Number.isFinite(parsed) && parsed >= 0 && parsed <= 100;
      },
      { message: "providers.validation.commissionRange" },
    ),
});

export type CommissionRateFormValues = z.infer<typeof commissionRateSchema>;
