export enum MoodleQuestionType {
  SINGLE_CHOICE = 'single_choice',
  MULTIPLE_CHOICE = 'multiple_choice',
  TRUE_FALSE = 'true_false',
  SHORT_TEXT = 'short_text',
  NUMERICAL = 'numerical',
  ESSAY = 'essay',
  MATCH = 'match',
  SELECT_MISSING_WORD = 'select_missing_word',
  DRAG_DROP_TEXT = 'drag_drop_text',
  ORDERING = 'ordering',
  UNKNOWN = 'unknown'
}

export interface AnswerOption {
  index: number;
  text: string;
}

// ==== Queries sent to LLM ====

export interface SingleChoiceQuery {
  question_type: MoodleQuestionType.SINGLE_CHOICE;
  question_text: string;
  answer_options: AnswerOption[];
}

export interface MultipleChoiceQuery {
  question_type: MoodleQuestionType.MULTIPLE_CHOICE;
  question_text: string;
  answer_options: AnswerOption[];
}

export interface TrueFalseQuery {
  question_type: MoodleQuestionType.TRUE_FALSE;
  question_text: string;
}

export interface ShortTextQuery {
  question_type: MoodleQuestionType.SHORT_TEXT;
  question_text: string;
}

export interface NumericalQuery {
  question_type: MoodleQuestionType.NUMERICAL;
  question_text: string;
}

export interface EssayQuery {
  question_type: MoodleQuestionType.ESSAY;
  question_text: string;
  format: 'plain_text' | 'html';
  initial_text?: string;
}

export interface MatchQuery {
  question_type: MoodleQuestionType.MATCH;
  question_text: string;
  sub_questions: { index: number; text: string }[];
  options: { index: number; text: string }[];
}

export interface SelectMissingWordQuery {
  question_type: MoodleQuestionType.SELECT_MISSING_WORD;
  question_text: string;
  drop_downs: { index: number; options: { index: number; text: string }[] }[];
}

export interface DragDropTextQuery {
  question_type: MoodleQuestionType.DRAG_DROP_TEXT;
  question_text: string;
  draggables: { index: number; text: string }[];
}

export interface OrderingQuery {
  question_type: MoodleQuestionType.ORDERING;
  question_text: string;
  items: { index: number; text: string }[];
}

export type MoodleQuestionQuery =
  | SingleChoiceQuery
  | MultipleChoiceQuery
  | TrueFalseQuery
  | ShortTextQuery
  | NumericalQuery
  | EssayQuery
  | MatchQuery
  | SelectMissingWordQuery
  | DragDropTextQuery
  | OrderingQuery;

// ==== Expected LLM Responses ====

export interface SingleChoiceResponse {
  question_type: MoodleQuestionType.SINGLE_CHOICE;
  correct_answer: { index: number };
}

export interface MultipleChoiceResponse {
  question_type: MoodleQuestionType.MULTIPLE_CHOICE;
  correct_answer: { indexes: number[] };
}

export interface TrueFalseResponse {
  question_type: MoodleQuestionType.TRUE_FALSE;
  correct_answer: boolean;
}

export interface ShortTextResponse {
  question_type: MoodleQuestionType.SHORT_TEXT;
  correct_answer: string;
}

export interface NumericalResponse {
  question_type: MoodleQuestionType.NUMERICAL;
  correct_answer: number;
}

export interface EssayResponse {
  question_type: MoodleQuestionType.ESSAY;
  correct_answer: string;
}

export interface MatchResponse {
  question_type: MoodleQuestionType.MATCH;
  correct_answers: { sub_question_index: number; option_index: number }[];
}

export interface SelectMissingWordResponse {
  question_type: MoodleQuestionType.SELECT_MISSING_WORD;
  correct_answers: { drop_down_index: number; option_index: number }[];
}

export interface DragDropTextResponse {
  question_type: MoodleQuestionType.DRAG_DROP_TEXT;
  correct_answers: { blank_index: number; draggable_index: number }[];
}

export interface OrderingResponse {
  question_type: MoodleQuestionType.ORDERING;
  correct_order: { indexes: number[] };
}

export type MoodleQuestionResponse =
  | SingleChoiceResponse
  | MultipleChoiceResponse
  | TrueFalseResponse
  | ShortTextResponse
  | NumericalResponse
  | EssayResponse
  | MatchResponse
  | SelectMissingWordResponse
  | DragDropTextResponse
  | OrderingResponse;
