import Foundation
import SwiftData

@Model
final class TypeCount {
    @Attribute(.unique) var id: UUID
    @Attribute var typeIdentifier: String
    @Attribute var displayName: String
    @Attribute var count: Int
    @Attribute var hash: String
    @Attribute var earliestDate: Date?
    @Attribute var latestDate: Date?
    @Attribute var quality: SnapshotQuality
    @Attribute var isUnsupported: Bool
    @Attribute var snapshot: HealthSnapshot?
    @Relationship(deleteRule: .cascade, inverse: \YearlyCount.typeCount)
    var yearlyCounts: [YearlyCount]?

    init(typeIdentifier: String, displayName: String, count: Int, quality: SnapshotQuality = SnapshotQuality.complete) {
        self.id = UUID()
        self.typeIdentifier = typeIdentifier
        self.displayName = displayName
        self.count = count
        self.hash = ""
        self.earliestDate = nil
        self.latestDate = nil
        self.quality = quality
        self.isUnsupported = false
        self.snapshot = nil
        self.yearlyCounts = []
    }
}
