import Foundation
import SwiftData

@Model
final class ConfirmedScanRecord {
    var confirmedAt: Date
    var cardName: String
    var cardNumber: String
    var setIdentifier: String
    var rarity: String
    var recognitionSource: String
    var confidence: String
    var rawTextPreview: String

    init(
        confirmedAt: Date = .now,
        cardName: String,
        cardNumber: String,
        setIdentifier: String,
        rarity: String,
        recognitionSource: String,
        confidence: String,
        rawTextPreview: String
    ) {
        self.confirmedAt = confirmedAt
        self.cardName = cardName
        self.cardNumber = cardNumber
        self.setIdentifier = setIdentifier
        self.rarity = rarity
        self.recognitionSource = recognitionSource
        self.confidence = confidence
        self.rawTextPreview = rawTextPreview
    }

    convenience init(draft: CardRecognitionDraft) {
        self.init(
            cardName: draft.cardName,
            cardNumber: draft.cardNumber,
            setIdentifier: draft.setIdentifier,
            rarity: draft.rarity,
            recognitionSource: draft.source.rawValue,
            confidence: draft.confidence.rawValue,
            rawTextPreview: String(draft.rawText.prefix(240))
        )
    }
}
