import XCTest
@testable import FchatiApp

final class RelayAPIResponseTests: XCTestCase {
    func testPairingCreateResponseDecodesServerPayload() throws {
        let data = Data(
            """
            {"code":"FCHT-AB3K7Q","token":"creator-token","peerID":"creator-id","expiresAt":"2026-07-26T12:00:00Z"}
            """.utf8
        )

        let response = try JSONDecoder().decode(PairingCreateResponse.self, from: data)

        XCTAssertEqual(response.code, "FCHT-AB3K7Q")
        XCTAssertEqual(response.peerID, "creator-id")
    }

    func testPairingJoinAndFileUploadResponsesDecodeServerPayloads() throws {
        let pairingData = Data(
            """
            {"token":"joiner-token","peerID":"joiner-id","peer":{"id":"creator-id","displayName":"Alex"}}
            """.utf8
        )
        let fileData = Data(
            """
            {"id":"file-id","name":"photo.jpg","size":128}
            """.utf8
        )

        let pairingResponse = try JSONDecoder().decode(PairingJoinResponse.self, from: pairingData)
        let fileResponse = try JSONDecoder().decode(FileUploadResponse.self, from: fileData)

        XCTAssertEqual(pairingResponse.peer, PeerInfo(id: "creator-id", displayName: "Alex"))
        XCTAssertEqual(fileResponse, FileUploadResponse(id: "file-id", name: "photo.jpg", size: 128))
    }
}
