//
//  ColorExtensionGeneratorTests.swift
//  
//
//  Created by Thibaut Schmitt on 05/09/2022.
//

import Foundation
import XCTest
import ToolCore

@testable import ResgenSwift

final class ColorExtensionGeneratorTests: XCTestCase {
    
    func test_uiKit_GeneratedExtensionContent() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(
            colors: colors,
            isStatic: false,
            extensionName: "GenColors",
            isSwiftUI: false,
            visibility: .public,
            assetBundle: .main
        )
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import UIKit

        extension GenColors {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            @objc public var colorOne: UIColor {
                UIColor(named: "colorOne", in: Bundle.main, compatibleWith: nil)!
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            @objc public var colorTwo: UIColor {
                UIColor(named: "colorTwo", in: Bundle.main, compatibleWith: nil)!
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_uiKit_GeneratedExtensionContentForIsStatic() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(
            colors: colors,
            isStatic: true,
            extensionName: "GenColor",
            isSwiftUI: false,
            visibility: .public,
            assetBundle: .module
        )
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import UIKit

        extension GenColor {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            public static var colorOne: UIColor {
                UIColor(named: "colorOne", in: Bundle.module, compatibleWith: nil)!
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            public static var colorTwo: UIColor {
                UIColor(named: "colorTwo", in: Bundle.module, compatibleWith: nil)!
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_swiftUI_GeneratedExtensionContent() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(
            colors: colors,
            isStatic: false,
            extensionName: "GenColors",
            isSwiftUI: true,
            visibility: .package,
            assetBundle: .main
        )
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import SwiftUI

        extension GenColors {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            package var colorOne: Color {
                Color("colorOne", bundle: Bundle.main)
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            package var colorTwo: Color {
                Color("colorTwo", bundle: Bundle.main)
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
    
    func test_swiftUI_GeneratedExtensionContentForIsStatic() {
        // Given
        let colors = [
            ParsedColor(name: "colorOne", light: "#FF00FF", dark: "#00FF00"),
            ParsedColor(name: "colorTwo", light: "#F0F0F0", dark: "#0F0F0F")
        ]
        
        // When
        let extensionContent = ColorExtensionGenerator.getExtensionContent(
            colors: colors,
            isStatic: true,
            extensionName: "GenColor",
            isSwiftUI: true,
            visibility: .internal,
            assetBundle: .module
        )
        
        // Expect
        let expect = """
        // Generated by ResgenSwift.Color \(ResgenSwiftVersion)

        import SwiftUI

        extension GenColor {
        
            /// Color colorOne is #FF00FF (light) or #00FF00 (dark)"
            internal static var colorOne: Color {
                Color("colorOne", bundle: Bundle.module)
            }
        
            /// Color colorTwo is #F0F0F0 (light) or #0F0F0F (dark)"
            internal static var colorTwo: Color {
                Color("colorTwo", bundle: Bundle.module)
            }
        }
        """
        
        XCTAssertEqual(extensionContent.adaptForXCTest(), expect.adaptForXCTest())
    }
}
