import { z } from "zod";

const usdtAmountSchema = z
    .string()
    .trim()
    .regex(/^(0|[1-9]\d*)(\.\d{1,6})?$/, "金额USDT最多支持 6 位小数")
    .refine((value) => !/^0(?:\.0{1,6})?$/.test(value), "金额USDT必须大于 0");

export const rechargeProductSchema = z.object({
    amountUsdt: usdtAmountSchema,
    audienceType: z.enum(["normal", "coin_seller"]),
    coinAmount: z.coerce.number().int("获得金币数必须是整数").positive("获得金币数必须大于 0"),
    description: z.string().trim().max(512, "描述不能超过 512 个字符").default(""),
    enabled: z.boolean(),
    platform: z.enum(["android", "ios", "web"]),
    productName: z.string().trim().min(1, "请填写产品名称").max(128, "产品名称不能超过 128 个字符"),
    regionIds: z.array(z.coerce.number().int().positive()).min(1, "请选择支持区域"),
});

export type RechargeProductForm = z.infer<typeof rechargeProductSchema>;

export const thirdPartyPaymentRateSyncSchema = z.object({
    markupPercent: z
        .string()
        .trim()
        .min(1, "请填写汇率上浮比例")
        .regex(/^(?:\d+|\d+\.\d{1,4})$/, "汇率上浮比例最多支持 4 位小数")
        .transform(Number)
        .pipe(z.number().min(0, "汇率上浮比例不能小于 0").max(100, "汇率上浮比例不能大于 100")),
});

export type ThirdPartyPaymentRateSyncForm = z.infer<typeof thirdPartyPaymentRateSyncSchema>;
