import AppLibrary
import Hummingbird
import HummingbirdTesting
import Testing

@Suite("AppBuilder", .tags(.builder))
struct AppBuilderTests {

    // MARK: Properties

    private let appBuilder = AppBuilder(
        appName: "DoxyTest",
        archivesFolder: "Resources/Archives/Test"
    )
    private let arguments = TestArguments()

    // MARK: Route tests
    
    @Test(arguments: zip([String].uris, [HTTPResponse.Status].statuses))
    func routes(
        uri: String,
        expects status: HTTPResponse.Status
    ) async throws {
        let app = try await appBuilder(arguments)

        try await app.test(.router) { client in
            try await client.execute(
                uri: uri,
                method: .get
            ) { response in
                #expect(response.status == status)
            }
        }
    }

}

// MARK: - Collection+HTTPResponseStatus

private extension Collection where Element == HTTPResponse.Status {

    // MARK: Computed

    static var statuses: [Element] {[
        .notFound,
        .notFound,
        .notFound,
        .notFound,
        .seeOther,
        .seeOther,
        .notImplemented,
        .seeOther,
        .seeOther,
        .seeOther,
        .seeOther,
        .notImplemented,
        .seeOther,
        .seeOther,
    ]}
    
}

// MARK: - Collection+String

private extension Collection where Element == String {
    
    // MARK: Computed
    
    static var uris: [Element] {[
        "/",
        "/index.html",
        "/xxx",
        "/archives",
        "/archives/SomeArchive",
        "/archives/SomeArchive/",
        "/archives/SomeArchive/index.html",
        "/archives/SomeArchive/documentation",
        "/archives/SomeArchive/tutorials",
        "/archives/SlothCreator",
        "/archives/SlothCreator/",
        "/archives/SlothCreator/index.html",
        "/archives/SlothCreator/documentation",
        "/archives/SlothCreator/tutorials",
    ]}
    
}
