import Foundation
import SwiftData

/// Per-airframe enrichment cached locally (and synced via CloudKit so we
/// only scrape jetphotos once per airframe across all of a user's
/// devices). Keyed by registration. Currently captures first-flight /
/// delivery dates so we can render "this plane is 8 years old" in the
/// detail sheet.
@Model
final class AirframeMetadata {
    var registration: String = ""    // "N281WN" — uppercase
    var firstFlightDate: Date?
    var deliveryDate: Date?
    var scrapedAt: Date = Date()

    init(
        registration: String,
        firstFlightDate: Date? = nil,
        deliveryDate: Date? = nil,
        scrapedAt: Date = Date()
    ) {
        self.registration = registration.uppercased()
        self.firstFlightDate = firstFlightDate
        self.deliveryDate = deliveryDate
        self.scrapedAt = scrapedAt
    }
}
