import Foundation
import SharedModels

enum QuizType: String, CaseIterable, Identifiable, Sendable {
    case mcEnToEs = "mc_en_to_es"
    case mcEsToEn = "mc_es_to_en"
    case typingEnToEs = "typing_en_to_es"
    case typingEsToEn = "typing_es_to_en"
    case handwritingEnToEs = "hw_en_to_es"
    case handwritingEsToEn = "hw_es_to_en"
    case completeSentenceES = "complete_sentence_es"
    case checkpoint = "checkpoint"

    var id: String { rawValue }

    /// Quiz types shown in the weekly test picker (excludes checkpoint).
    static var weeklyQuizTypes: [QuizType] {
        allCases.filter { $0 != .checkpoint }
    }

    var label: String {
        switch self {
        case .mcEnToEs: "Multiple Choice: EN → ES"
        case .mcEsToEn: "Multiple Choice: ES → EN"
        case .typingEnToEs: "Fill in the Blank: EN → ES"
        case .typingEsToEn: "Fill in the Blank: ES → EN"
        case .handwritingEnToEs: "Handwriting: EN → ES"
        case .handwritingEsToEn: "Handwriting: ES → EN"
        case .completeSentenceES: "Complete the Sentence"
        case .checkpoint: "Checkpoint Exam"
        }
    }

    var icon: String {
        switch self {
        case .mcEnToEs, .mcEsToEn: "list.bullet"
        case .typingEnToEs, .typingEsToEn: "keyboard"
        case .handwritingEnToEs, .handwritingEsToEn: "pencil.and.outline"
        case .completeSentenceES: "text.badge.checkmark"
        case .checkpoint: "checkmark.seal"
        }
    }

    var description: String {
        switch self {
        case .mcEnToEs: "See English, pick the Spanish translation"
        case .mcEsToEn: "See Spanish, pick the English translation"
        case .typingEnToEs: "See English, type the Spanish word"
        case .typingEsToEn: "See Spanish, type the English word"
        case .handwritingEnToEs: "See English, handwrite the Spanish word"
        case .handwritingEsToEn: "See Spanish, handwrite the English word"
        case .completeSentenceES: "Read a Spanish sentence and pick the missing word"
        case .checkpoint: "Cumulative review of all weeks so far"
        }
    }

    /// What's shown as the prompt
    var promptLanguage: String {
        switch self {
        case .mcEnToEs, .typingEnToEs, .handwritingEnToEs: "English"
        case .mcEsToEn, .typingEsToEn, .handwritingEsToEn, .completeSentenceES, .checkpoint: "Spanish"
        }
    }

    var answerLanguage: String {
        switch self {
        case .mcEnToEs, .typingEnToEs, .handwritingEnToEs, .completeSentenceES: "Spanish"
        case .mcEsToEn, .typingEsToEn, .handwritingEsToEn, .checkpoint: "English"
        }
    }

    var isMultipleChoice: Bool {
        switch self {
        case .mcEnToEs, .mcEsToEn, .completeSentenceES, .checkpoint: true
        case .typingEnToEs, .typingEsToEn, .handwritingEnToEs, .handwritingEsToEn: false
        }
    }

    var isHandwriting: Bool {
        switch self {
        case .handwritingEnToEs, .handwritingEsToEn: true
        default: false
        }
    }

    var isCompleteSentence: Bool {
        self == .completeSentenceES
    }

    func prompt(for card: VocabCard) -> String {
        switch self {
        case .mcEnToEs, .typingEnToEs, .handwritingEnToEs: card.back
        case .mcEsToEn, .typingEsToEn, .handwritingEsToEn, .completeSentenceES, .checkpoint: card.front
        }
    }

    func answer(for card: VocabCard) -> String {
        switch self {
        case .mcEnToEs, .typingEnToEs, .handwritingEnToEs, .completeSentenceES: card.front
        case .mcEsToEn, .typingEsToEn, .handwritingEsToEn, .checkpoint: card.back
        }
    }
}
