// 通知偏好 Zod schema
// 依据：02-architecture-design.md §14 通知偏好数据模型、project_rules §3.8 输入验证
// - 三维矩阵：children[eventType][channel] = enabled
// - 用于表单校验 + localStorage 序列化校验

import { z } from "zod";

const NOTIFICATION_EVENT_TYPES = [
  "grade_recorded",
  "homework_graded",
  "homework_assigned",
  "exam_published",
  "attendance_alert",
  "school_announcement",
  "teacher_message",
  "fee_reminder",
  "event_invitation",
] as const;

const NOTIFICATION_CHANNELS = [
  "in_app",
  "push",
  "sms",
  "email",
  "wechat",
] as const;

const channelPrefSchema = z
  .object({
    in_app: z.boolean().optional(),
    push: z.boolean().optional(),
    sms: z.boolean().optional(),
    email: z.boolean().optional(),
    wechat: z.boolean().optional(),
  })
  .partial();

const eventTypePrefSchema = z.record(
  z.enum(NOTIFICATION_EVENT_TYPES),
  channelPrefSchema,
);

export const notificationPreferencesSchema = z.object({
  parentId: z.string(),
  preferences: z.record(z.string(), eventTypePrefSchema),
  defaults: eventTypePrefSchema,
  updatedAt: z.string(),
});

export type NotificationPreferencesInput = z.input<
  typeof notificationPreferencesSchema
>;
export type NotificationPreferencesOutput = z.output<
  typeof notificationPreferencesSchema
>;

export { NOTIFICATION_EVENT_TYPES, NOTIFICATION_CHANNELS };
