import SwiftData
import Foundation

/// SRS record for non-verb vocab cards (nouns, adjectives, …). Keyed by
/// `(partOfSpeech, lexemeId, drillMode)` so a noun's gender drill and its
/// English-recall drill progress independently. Lives in the cloud container
/// alongside `VerbReviewCard` so vocab progress syncs across devices.
///
/// CloudKit-synced; uniqueness on `id` is enforced via fetch-or-create in
/// `LexemeReviewStore` since CloudKit forbids `@Attribute(.unique)`.
@Model
final class LexemeReviewCard {
    var id: String = ""
    var lexemeId: String = ""
    var partOfSpeech: String = ""
    var drillMode: String = ""

    var easeFactor: Double = 2.5
    var interval: Int = 0
    var repetitions: Int = 0
    var dueDate: Date = Date()
    var lastReviewDate: Date?

    init(lexemeId: String, partOfSpeech: String, drillMode: String) {
        self.id = Self.makeId(
            lexemeId: lexemeId,
            partOfSpeech: partOfSpeech,
            drillMode: drillMode
        )
        self.lexemeId = lexemeId
        self.partOfSpeech = partOfSpeech
        self.drillMode = drillMode
    }

    static func makeId(lexemeId: String, partOfSpeech: String, drillMode: String) -> String {
        "\(partOfSpeech)|\(lexemeId)|\(drillMode)"
    }
}
