import SwiftData
import Foundation

public enum VerbLevel: String, CaseIterable, Sendable {
    case basic
    case elementary
    case intermediate
    case advanced
    case expert

    public var displayName: String { rawValue.capitalized }
}

@Model
public final class Verb {
    public var id: Int = 0
    public var infinitive: String = ""
    public var english: String = ""
    public var rank: Int = 0
    public var ending: String = ""
    public var reflexive: Int = 0
    public var level: String = ""

    @Relationship(deleteRule: .cascade, inverse: \VerbForm.verb)
    public var forms: [VerbForm]?

    public init(id: Int, infinitive: String, english: String, rank: Int, ending: String, reflexive: Int, level: String) {
        self.id = id
        self.infinitive = infinitive
        self.english = english
        self.rank = rank
        self.ending = ending
        self.reflexive = reflexive
        self.level = level
    }
}

public enum VerbLevelGroup: String, CaseIterable, Sendable {
    case basic = "basic"
    case elementary = "elementary"
    case intermediate = "intermediate"
    case advanced = "advanced"
    case expert = "expert"

    public static func dataLevels(for selectedLevel: String) -> Set<String> {
        switch selectedLevel {
        case Self.basic.rawValue:
            return ["basic"]
        case Self.elementary.rawValue:
            return ["elementary", "elementary_1", "elementary_2", "elementary_3"]
        case Self.intermediate.rawValue:
            return ["intermediate", "intermediate_1", "intermediate_2", "intermediate_3", "intermediate_4"]
        case Self.advanced.rawValue:
            return ["advanced"]
        case Self.expert.rawValue:
            return ["expert"]
        default:
            return [selectedLevel]
        }
    }

    public static func matches(_ dataLevel: String, selectedLevel: String) -> Bool {
        dataLevels(for: selectedLevel).contains(dataLevel)
    }
}
