import { MoodleQuestionType } from '../../types/question-types';

export const QuestionSchemas: Record<MoodleQuestionType, any> = {
  [MoodleQuestionType.SINGLE_CHOICE]: {
    name: 'single_choice_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.SINGLE_CHOICE] },
        correct_answer: {
          type: 'object',
          properties: { index: { type: 'integer' } },
          required: ['index'],
          additionalProperties: false
        }
      },
      required: ['question_type', 'correct_answer'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.MULTIPLE_CHOICE]: {
    name: 'multiple_choice_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.MULTIPLE_CHOICE] },
        correct_answer: {
          type: 'object',
          properties: {
            indexes: {
              type: 'array',
              items: { type: 'integer' }
            }
          },
          required: ['indexes'],
          additionalProperties: false
        }
      },
      required: ['question_type', 'correct_answer'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.TRUE_FALSE]: {
    name: 'true_false_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.TRUE_FALSE] },
        correct_answer: { type: 'boolean' }
      },
      required: ['question_type', 'correct_answer'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.SHORT_TEXT]: {
    name: 'short_text_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.SHORT_TEXT] },
        correct_answer: { type: 'string' }
      },
      required: ['question_type', 'correct_answer'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.NUMERICAL]: {
    name: 'numerical_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.NUMERICAL] },
        correct_answer: { type: 'number' }
      },
      required: ['question_type', 'correct_answer'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.ESSAY]: {
    name: 'essay_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.ESSAY] },
        correct_answer: { type: 'string' }
      },
      required: ['question_type', 'correct_answer'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.MATCH]: {
    name: 'match_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.MATCH] },
        correct_answers: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              sub_question_index: { type: 'integer' },
              option_index: { type: 'integer' }
            },
            required: ['sub_question_index', 'option_index'],
            additionalProperties: false
          }
        }
      },
      required: ['question_type', 'correct_answers'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.SELECT_MISSING_WORD]: {
    name: 'select_missing_word_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.SELECT_MISSING_WORD] },
        correct_answers: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              drop_down_index: { type: 'integer' },
              option_index: { type: 'integer' }
            },
            required: ['drop_down_index', 'option_index'],
            additionalProperties: false
          }
        }
      },
      required: ['question_type', 'correct_answers'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.DRAG_DROP_TEXT]: {
    name: 'drag_drop_text_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.DRAG_DROP_TEXT] },
        correct_answers: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              blank_index: { type: 'integer' },
              draggable_index: { type: 'integer' }
            },
            required: ['blank_index', 'draggable_index'],
            additionalProperties: false
          }
        }
      },
      required: ['question_type', 'correct_answers'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.ORDERING]: {
    name: 'ordering_response',
    strict: true,
    schema: {
      type: 'object',
      properties: {
        question_type: { type: 'string', enum: [MoodleQuestionType.ORDERING] },
        correct_order: {
          type: 'object',
          properties: {
            indexes: {
              type: 'array',
              items: { type: 'integer' }
            }
          },
          required: ['indexes'],
          additionalProperties: false
        }
      },
      required: ['question_type', 'correct_order'],
      additionalProperties: false
    }
  },
  [MoodleQuestionType.UNKNOWN]: undefined
};
