import { z } from "zod";

/**
 * Preferences 模块 DTO + Zod 校验。
 *
 * 对齐 proto msg.proto NotificationPreference 字段。
 */

const channelEnum = z.enum(["in_app", "email", "sms", "push", "wechat"]);
const typeEnum = z.enum([
  "system",
  "exam",
  "homework",
  "grade",
  "attendance",
  "mastery",
]);

export const preferenceSchema = z.object({
  type: typeEnum,
  channels: z.array(channelEnum).min(1),
  frequencyLimit: z.number().int().min(0).optional(),
  quietHoursStart: z.string().max(8).optional(),
  quietHoursEnd: z.string().max(8).optional(),
  quietHoursTimezone: z.string().max(64).optional(),
  enabled: z.boolean().default(true),
});

export type PreferenceDto = z.infer<typeof preferenceSchema>;

export const updatePreferencesSchema = z.object({
  userId: z.string().min(1),
  preferences: z.array(preferenceSchema).min(1),
});

export type UpdatePreferencesDto = z.infer<typeof updatePreferencesSchema>;
