import XCTest

@MainActor
final class PairingUITests: XCTestCase {

    override func setUpWithError() throws {
        continueAfterFailure = false
    }

    func testLaunchUnpairedShowsPairingFlow() throws {
        let app = XCUIApplication()
        app.launchUnpaired()

        // Assert PairingFlowView is showing
        let scanButton = app.buttons["Tap to Scan"]
        XCTAssertTrue(scanButton.waitForExistence(timeout: 5), "PairingFlowView should be visible on unpaired launch")
    }

    func testAutoPairingViaLaunchArgument() throws {
        guard let pairingURL = TestSidecar.freshPairURL() else {
            throw XCTSkip("Could not fetch fresh pair URL - sidecar may be down")
        }

        let app = XCUIApplication()
        app.launchWithPairing(url: pairingURL)

        let switcherButton = app.buttons["Switcher"]
        XCTAssertTrue(switcherButton.waitForExistence(timeout: 15),
                      "App should auto-pair and show MainTerminalView")
    }
}
