import { z } from "zod";

const benefitSchema = z.object({
    catalogPlaceholder: z.boolean().optional(),
    benefitCode: z.string().trim().min(1, "权益编码不能为空").max(96, "权益编码不能超过 96 个字符"),
    benefitType: z.enum(["decoration", "function"]),
    autoEquip: z.boolean(),
    executionScope: z.enum(["wallet", "room", "user", "notice"]),
    metadataJson: z.string().trim().max(4096, "权益元数据不能超过 4096 个字符"),
    name: z.string().trim().min(1, "权益名称不能为空").max(128, "权益名称不能超过 128 个字符"),
    resourceId: z.union([z.string(), z.number()]).optional(),
    resourceType: z.string().optional(),
    sortOrder: z.union([z.string(), z.number()]),
    status: z.enum(["active", "disabled"]),
    trialEnabled: z.boolean(),
    unlockLevel: z.number().int().positive(),
});

const levelSchema = z.object({
    benefits: z.array(benefitSchema),
    durationDays: z.union([z.string(), z.number()]),
    level: z.number().int().positive(),
    name: z.string().trim().min(1, "VIP名称不能为空").max(128, "VIP名称不能超过 128 个字符"),
    priceCoin: z.union([z.string(), z.number()]),
    rewardResourceGroupId: z.union([z.string(), z.number()]).optional(),
    sortOrder: z.union([z.string(), z.number()]),
    status: z.enum(["active", "disabled"]),
});

export const vipProgramFormSchema = z.object({
    enabled: z.boolean(),
    levelCount: z.union([z.string(), z.number()]),
    programType: z.enum(["legacy_timed", "tiered_privilege_v1"]),
});

export const vipConfigFormSchema = z.object({ levels: z.array(levelSchema).min(1, "请至少配置一个VIP等级") });
