import Foundation
import ForgejoKit
import Testing
@testable import Forji

struct WorkflowRunFilterTests {

    @Test func allFilterMapsToNilApiStatus() {
        #expect(WorkflowRunFilter.all.apiStatus == nil)
    }

    @Test func runningFilterMapsToRunningApiStatus() {
        #expect(WorkflowRunFilter.running.apiStatus == "running")
    }

    @Test func successFilterMapsToSuccessApiStatus() {
        #expect(WorkflowRunFilter.success.apiStatus == "success")
    }

    @Test func failureFilterMapsToFailureApiStatus() {
        #expect(WorkflowRunFilter.failure.apiStatus == "failure")
    }

    @Test func filterRawValueRoundTrip() {
        for filter in WorkflowRunFilter.allCases {
            let rebuilt = WorkflowRunFilter(rawValue: filter.rawValue)
            #expect(rebuilt == filter)
        }
    }

    @Test func filterAllCasesCount() {
        #expect(WorkflowRunFilter.allCases.count == 4)
    }

    @Test func filterLabelsArePresent() {
        for filter in WorkflowRunFilter.allCases {
            #expect(!filter.label.isEmpty)
        }
    }

    @Test func filterApiStatusValuesAreForgejoCompatible() {
        // Forgejo's known status enum: anything outside this set would be a
        // 400 from the API.
        let forgejoStatuses: Set<String> = [
            "success", "failure", "cancelled", "skipped",
            "running", "waiting", "blocked", "unknown",
        ]
        for filter in WorkflowRunFilter.allCases {
            if let status = filter.apiStatus {
                #expect(forgejoStatuses.contains(status), "Filter \(filter) sends \(status) which Forgejo doesn't accept")
            }
        }
    }
}
