/**
 * Content gRPC message types — 手动定义，对齐 content.proto。
 * 当 buf generate 生成 TS 类型后，可替换为生成类型。
 */

export type Empty = Record<string, never>;

export interface GrpcTextbook {
  id: string;
  title: string;
  subject_id: string;
  grade_id: string;
  version: string;
  status: string;
  tenant_id: string;
  metadata: Record<string, unknown> | null;
  created_at: number;
  updated_at: number;
}

export interface GrpcChapter {
  id: string;
  textbook_id: string;
  title: string;
  order: number;
  parent_id: string;
  status: string;
  created_at: number;
  updated_at: number;
}

export interface GrpcKnowledgePoint {
  id: string;
  chapter_id: string;
  title: string;
  description: string;
  difficulty: number;
  metadata: Record<string, unknown> | null;
  created_at: number;
  updated_at: number;
}

export interface GrpcQuestion {
  id: string;
  knowledge_point_id: string;
  type: string;
  content: string;
  options: Record<string, unknown> | null;
  answer: string;
  explanation: string;
  difficulty: number;
  status: string;
  source: string;
  created_by: string;
  metadata: Record<string, unknown> | null;
  created_at: number;
  updated_at: number;
}

// TextbookService requests
export interface CreateTextbookRequest {
  title: string;
  subject_id: string;
  grade_id: string;
  version?: string;
  metadata?: Record<string, unknown> | null;
}

export interface GetTextbookRequest {
  id: string;
}

export interface ListTextbooksRequest {
  subject_id?: string;
  grade_id?: string;
  page_token?: string;
  page_size?: number;
}

export interface ListTextbooksResponse {
  textbooks: GrpcTextbook[];
  next_page_token: string;
}

export interface UpdateTextbookRequest {
  id: string;
  title?: string;
  status?: string;
  metadata?: Record<string, unknown> | null;
}

export interface DeleteTextbookRequest {
  id: string;
}

// ChapterService requests
export interface CreateChapterRequest {
  textbook_id: string;
  title: string;
  order?: number;
  parent_id?: string;
}

export interface GetChapterRequest {
  id: string;
}

export interface ListChaptersRequest {
  textbook_id: string;
  parent_id?: string;
}

export interface ListChaptersResponse {
  chapters: GrpcChapter[];
}

export interface UpdateChapterRequest {
  id: string;
  title?: string;
  order?: number;
  status?: string;
}

export interface DeleteChapterRequest {
  id: string;
}

// KnowledgeGraphService requests
export interface GetPrerequisitesRequest {
  knowledge_point_id: string;
  depth?: number;
}

export interface KnowledgePointsResponse {
  points: GrpcKnowledgePoint[];
}

export interface GetLearningPathRequest {
  student_id: string;
  subject_id: string;
}

export interface LearningPath {
  points: GrpcKnowledgePoint[];
  recommended_order: string[];
}

export interface AddPrerequisiteRequest {
  kp_id: string;
  prerequisite_id: string;
}

export interface RemovePrerequisiteRequest {
  kp_id: string;
  prerequisite_id: string;
}

// QuestionService requests
export interface CreateQuestionRequest {
  knowledge_point_id: string;
  type: string;
  content: string;
  options?: Record<string, unknown> | null;
  answer: string;
  explanation?: string;
  difficulty?: number;
  source?: string;
  created_by: string;
  metadata?: Record<string, unknown> | null;
}

export interface BatchCreateQuestionsRequest {
  questions: CreateQuestionRequest[];
}

export interface BatchCreateQuestionsResponse {
  ids: string[];
  failed: BatchCreateFailure[];
}

export interface BatchCreateFailure {
  index: number;
  error: string;
}

export interface GetQuestionRequest {
  id: string;
}

export interface ListQuestionsRequest {
  knowledge_point_id?: string;
  type?: string;
  difficulty?: number;
  status?: string;
  page_token?: string;
  page_size?: number;
}

export interface ListQuestionsResponse {
  questions: GrpcQuestion[];
  next_page_token: string;
}

export interface UpdateQuestionRequest {
  id: string;
  content?: string;
  answer?: string;
  status?: string;
  options?: Record<string, unknown> | null;
  explanation?: string;
  difficulty?: number;
}

export interface DeleteQuestionRequest {
  id: string;
}

export interface PublishQuestionRequest {
  id: string;
}

export interface SearchQuestionsRequest {
  q: string;
  type?: string;
  difficulty?: number;
  knowledge_point_id?: string;
  page_token?: string;
  page_size?: number;
}

export interface SearchQuestionsResponse {
  questions: GrpcQuestion[];
  total: number;
  next_page_token: string;
}
