import XCTest
@testable import Flights

/// Tests for the standby tracking fields on the history flight model.
///
/// NOTE: The codebase's history record type is `LoggedFlight` (see
/// `Flights/Models/LoggedFlight.swift`). The task spec referred to it as
/// "HistoryFlight" — that name does not exist. These tests therefore
/// target `LoggedFlight`, which is the actual @Model SwiftData type that
/// owns `standbyOutcome` and the computed `wasStandby`.
///
/// Assumption to verify: there is no separate `HistoryFlight` type.
final class HistoryFlightModelTests: XCTestCase {

    // MARK: wasStandby

    func test_wasStandby_isTrue_whenOutcomeIsStandbyMade() {
        let flight = LoggedFlight(departureIATA: "LAX", arrivalIATA: "JFK")
        flight.standbyOutcome = "standby-made"
        XCTAssertTrue(flight.wasStandby,
                      "standby-made should count as a standby attempt")
    }

    func test_wasStandby_isTrue_whenOutcomeIsStandbyBumped() {
        let flight = LoggedFlight(departureIATA: "LAX", arrivalIATA: "JFK")
        flight.standbyOutcome = "standby-bumped"
        XCTAssertTrue(flight.wasStandby,
                      "standby-bumped should count as a standby attempt")
    }

    func test_wasStandby_isFalse_whenOutcomeIsConfirmed() {
        let flight = LoggedFlight(departureIATA: "LAX", arrivalIATA: "JFK")
        flight.standbyOutcome = "confirmed"
        XCTAssertFalse(flight.wasStandby,
                       "confirmed is a positive-space ticket, not standby")
    }

    func test_wasStandby_isFalse_whenOutcomeIsNil() {
        let flight = LoggedFlight(departureIATA: "LAX", arrivalIATA: "JFK")
        flight.standbyOutcome = nil
        XCTAssertFalse(flight.wasStandby,
                       "nil outcome (legacy / unmigrated) should not count as standby")
    }

    // MARK: Default init — all new standby fields nil

    func test_defaultInit_hasAllStandbyFieldsNil() {
        let flight = LoggedFlight()

        XCTAssertNil(flight.standbyOutcome,
                     "standbyOutcome must default to nil for CloudKit migration safety")
        XCTAssertNil(flight.standbyAttemptedAt,
                     "standbyAttemptedAt must default to nil")
        XCTAssertNil(flight.standbyClearedAt,
                     "standbyClearedAt must default to nil")
        XCTAssertNil(flight.standbyClass,
                     "standbyClass must default to nil")
        XCTAssertNil(flight.standbyNotes,
                     "standbyNotes must default to nil")

        // And the derived flag follows.
        XCTAssertFalse(flight.wasStandby,
                       "a freshly-constructed record is not a standby attempt")
    }
}
