/**
 * GraphQL operations - P5 扩展（通知中心 + AI 辅助）
 *
 * 维护者：ai13（teacher-portal）
 * 关联：02-architecture-design.md §5 实时推送、§6 AI 辅助
 *
 * schema 来源：teacher-bff.graphql（P5 扩展，MSW mock，待 ai03 在上游补 schema）
 * - 通知：myNotifications / markAsRead（push-gateway 实时推送 + GraphQL 持久化）
 * - AI：generateQuestion / generateLessonPlan / generateReport
 *
 * 注意：本文件独立于 graphql.ts（P2/P3），不修改共享文件，最后统一合并。
 */

import { gql } from "urql";

// ============ Types（通知中心） ============

export type NotificationType =
  | "HOMEWORK_SUBMITTED"
  | "EXAM_GRADED"
  | "BROADCAST"
  | "ROLE_CHANGED";

export interface NotificationItem {
  id: string;
  type: NotificationType;
  title: string;
  message: string;
  read: boolean;
  createdAt: string;
}

// ============ Types（AI 辅助） ============

export interface GenerateQuestionInput {
  subject: string;
  questionType: string;
  difficulty: string;
  knowledgePoints: string;
  count: number;
}

export interface GeneratedQuestion {
  id: string;
  question: string;
  options: string[];
  answer: string;
  explanation: string;
}

export interface GenerateLessonPlanInput {
  classId: string;
  subject: string;
  topic: string;
  objectives: string;
}

export interface GeneratedLessonPlan {
  id: string;
  content: string;
  summary: string;
}

export interface GenerateReportInput {
  classId: string;
  reportType: string;
  studentId?: string;
}

export interface GeneratedReport {
  id: string;
  content: string;
  summary: string;
  recommendations: string[];
}

// ============ Queries / Mutations ============

/** 通知列表查询 */
export const MyNotificationsQuery = gql`
  query MyNotifications($unreadOnly: Boolean) {
    myNotifications(unreadOnly: $unreadOnly) {
      id
      type
      title
      message
      read
      createdAt
    }
  }
`;

/** 标记已读 */
export const MarkAsReadMutation = gql`
  mutation MarkAsRead($id: ID!) {
    markAsRead(id: $id) {
      id
      read
    }
  }
`;

/** AI 辅助出题（SSE 流式，mock 用 ReadableStream） */
export const GenerateQuestionMutation = gql`
  mutation GenerateQuestion($input: GenerateQuestionInput!) {
    generateQuestion(input: $input) {
      id
      question
      options
      answer
      explanation
    }
  }
`;

/** AI 生成教案 */
export const GenerateLessonPlanMutation = gql`
  mutation GenerateLessonPlan($input: GenerateLessonPlanInput!) {
    generateLessonPlan(input: $input) {
      id
      content
      summary
    }
  }
`;

/** AI 学情报告 */
export const GenerateReportMutation = gql`
  mutation GenerateReport($input: GenerateReportInput!) {
    generateReport(input: $input) {
      id
      content
      summary
      recommendations
    }
  }
`;
