import Foundation
import SwiftData

/// User mark on a vocab card for "extra study" focus. Cloud-synced so the set
/// follows the user across devices. Denormalises card identity (deckId/front/
/// back) so the Course tab can resolve a marked-cards view without joining
/// against the local-only `VocabCard` store.
///
/// CloudKit forbids `@Attribute(.unique)`, so callers must fetch-or-create
/// by `id` to maintain uniqueness in code.
@Model
public final class ExtraStudyMark {
    /// Stable hash of (deckId, front, back, examplesES, examplesEN). Same
    /// shape as `CourseCardStore.reviewKey(for:)` so a mark and a review
    /// card describe the same logical card.
    public var id: String = ""

    public var deckId: String = ""
    public var courseName: String = ""
    public var weekNumber: Int = 0

    public var front: String = ""
    public var back: String = ""

    public var markedAt: Date = Date()

    public init(
        id: String,
        deckId: String,
        courseName: String,
        weekNumber: Int,
        front: String,
        back: String,
        markedAt: Date = Date()
    ) {
        self.id = id
        self.deckId = deckId
        self.courseName = courseName
        self.weekNumber = weekNumber
        self.front = front
        self.back = back
        self.markedAt = markedAt
    }
}
