import XCTest
import SwiftUI
@testable import Riotact

class RiotactTests: XCTestCase {

    func testImageAssets() {
        XCTAssertEqual(Set(ImageName.allCases.map { $0.rawValue }).count, ImageName.allCases.count)
        XCTAssertGreaterThan(ImageName.allCases.compactMap { $0.image }.count, 0)
        XCTAssertEqual(ImageName.allCases.compactMap { $0.uiImage }.count, ImageName.allCases.count)
        ImageName.allCases.forEach {
            XCTAssertNotNil($0.uiImage, "No image named \($0.rawValue)")
        }
    }
    
    func testNamedSystemImages() {
        XCTAssertEqual(Set(ImageName.System.allCases.map { $0.rawValue }).count, ImageName.System.allCases.count)
        XCTAssertGreaterThan(ImageName.System.allCases.compactMap { $0.uiImage }.count, 0)
        XCTAssertEqual(ImageName.System.allCases.compactMap { $0.uiImage }.count, ImageName.System.allCases.count)
        ImageName.System.allCases.forEach {
            XCTAssertNotNil($0.uiImage, "No system image named \($0.name)")
        }
    }
    
    func testColorAssets() {
        XCTAssertEqual(Set(ColorName.allCases.map { $0.rawValue }).count, ColorName.allCases.count)
        XCTAssertGreaterThan(ColorName.allCases.compactMap { $0.color }.count, 0)
        XCTAssertEqual(ColorName.allCases.compactMap { $0.color }.count, ColorName.allCases.count)
        ColorName.allCases.forEach { colorName in
            if colorName.hasVariations {
                XCTAssertNotNil(colorName.color(variation: .primary), "No primary color for \(colorName.rawValue)")
                XCTAssertNotNil(colorName.color(variation: .secondary), "No secondary color for \(colorName.rawValue)")
                XCTAssertNotNil(colorName.color(variation: .tertiary), "No tertiary color for \(colorName.rawValue)")

            } else {
                XCTAssertNotNil(colorName.color, "No color for \(colorName.rawValue)")
            }
        }
    }
    
    func testColorWithColorScheme() {
        let assetLightColor = ColorName.background.color(variation: .primary, colorScheme: .light)
        let assetDarkColor = ColorName.background.color(variation: .primary, colorScheme: .dark)
        
        XCTAssertNotEqual(assetDarkColor, assetLightColor)
    }
    
    func testPolicyPageDecoding() async {
        let riotKit = RiotKit()
        let expectedPageCount: Int = 3
        var pages: [PolicyPage] = []
        
        do {
            pages = try await riotKit.fetchPolicyPages()
        } catch {
            XCTFail(error.localizedDescription)
            
        }
        XCTAssertEqual(pages.count, expectedPageCount)
    }
}
