import Foundation
import SwiftData

@Model final class SnapshotDelta {
    @Attribute(.unique) var id: UUID
    @Attribute var fromSnapshotID: UUID
    @Attribute var toSnapshotID: UUID
    @Attribute var deviceID: String
    @Attribute var computedAt: Date
    @Attribute var checksumBefore: String
    @Attribute var checksumAfter: String
    @Attribute var isCloudKitImported: Bool
    @Relationship(deleteRule: .cascade, inverse: \TypeDelta.delta)
    var typeDeltas: [TypeDelta]?

    init(fromSnapshotID: UUID, toSnapshotID: UUID, deviceID: String) {
        self.id = UUID()
        self.fromSnapshotID = fromSnapshotID
        self.toSnapshotID = toSnapshotID
        self.deviceID = deviceID
        self.computedAt = Date.now
        self.checksumBefore = ""
        self.checksumAfter = ""
        self.isCloudKitImported = false
        self.typeDeltas = []
    }
}
