import Foundation
import Observation
import SwiftData

@Observable
final class StatsViewModel {
    var records: [StatsRecord] = []

    func loadStats(context: ModelContext) {
        let descriptor = FetchDescriptor<StatsRecord>()
        records = (try? context.fetch(descriptor)) ?? []
    }

    func stats(for variant: GameVariant, difficulty: Difficulty) -> StatsRecord? {
        records.first { $0.variant == variant.rawValue && $0.difficulty == difficulty.rawValue }
    }
}
