/**
 * parent-bff GraphQL 类型定义（对齐 02-architecture-design.md §4.2 + parent-bff.graphql SDL）。
 *
 * 这些 TypeScript 接口用于 Resolver 返回值类型校验，与 GraphQL Schema 字段一一对应。
 * 字段映射规则见 02 §3.3（proto message → BFF DTO 映射）。
 */

export type DataScope =
  "SELF" | "CHILDREN" | "CLASS" | "GRADE" | "SCHOOL" | "DISTRICT" | "ALL";

export interface ParentType {
  id: string;
  email: string;
  name: string;
  avatar?: string | null;
  roles: string[];
  dataScope: DataScope;
}

export interface ViewportItemType {
  key: string;
  label: string;
  route: string;
  icon?: string | null;
  sortOrder: string;
  requiredPermission?: string | null;
}

export interface ClassInfoType {
  id: string;
  name: string;
  gradeId: string;
}

export interface GradeType {
  id: string;
  examId: string;
  examTitle: string;
  subject: string;
  score: number;
  rank?: number | null;
  gradedAt: string;
}

export interface PaginationType {
  page: number;
  pageSize: number;
  total: number;
}

export interface GradePageType {
  items: GradeType[];
  pagination: PaginationType;
}

export type HomeworkStatus =
  "NOT_SUBMITTED" | "SUBMITTED" | "GRADED" | "OVERDUE";

export interface HomeworkType {
  id: string;
  title: string;
  classId: string;
  dueDate: string;
  status: HomeworkStatus;
  submittedAt?: string | null;
}

export type ExamStatus =
  "DRAFT" | "PUBLISHED" | "IN_PROGRESS" | "GRADING" | "SCORED" | "ARCHIVED";

export interface ExamType {
  id: string;
  title: string;
  classId: string;
  status: ExamStatus;
  examDate: string;
  publishedAt?: string | null;
}

export interface WeaknessTopicType {
  knowledgePointId: string;
  name: string;
  subject: string;
  masteryRate: number;
}

export interface TrendPointType {
  date: string;
  score: number;
  subject?: string | null;
}

export interface ChildAnalyticsType {
  childId: string;
  weakness: WeaknessTopicType[];
  trend: TrendPointType[];
  classRank?: number | null;
  classAverage?: number | null;
}

export interface ChildType {
  id: string;
  name: string;
  grade: string;
  class: ClassInfoType;
  lastGrade?: GradeType | null;
  grades?: GradePageType;
  homework?: HomeworkType[];
  exams?: ExamType[];
  analytics?: ChildAnalyticsType;
}

export type NotificationType =
  "SYSTEM" | "EXAM" | "HOMEWORK" | "GRADE" | "ATTENDANCE" | "ANNOUNCEMENT";

export interface NotificationItem {
  id: string;
  type: NotificationType;
  title: string;
  content: string;
  read: boolean;
  childId?: string | null;
  createdAt: string;
}

export type NotificationChannel = "APP" | "SMS" | "EMAIL" | "WECHAT";

export interface NotificationEventTypes {
  gradeReleased: boolean;
  homeworkGraded: boolean;
  examPublished: boolean;
  attendanceAlert: boolean;
  schoolAnnouncement: boolean;
}

export interface NotificationPreferencesType {
  channels: NotificationChannel[];
  eventTypes: NotificationEventTypes;
}

export interface DashboardDataType {
  parent: ParentType | null;
  children: ChildType[];
  viewports: ViewportItemType[];
  unreadNotifications: number;
  degraded: boolean;
}

export interface DateRangeInput {
  start: string;
  end: string;
}

export interface SelectChildResultType {
  childId: string;
  selectedAt: string;
  audited: boolean;
}

export interface UpdateNotificationPreferencesInput {
  channels: NotificationChannel[];
  eventTypes: Partial<NotificationEventTypes>;
}
