import Foundation
import ComposeApp

// MARK: - Bool to KotlinBoolean

extension Bool {
    /// Convert Swift Bool to Kotlin Boolean
    var asKotlin: KotlinBoolean {
        KotlinBoolean(bool: self)
    }
}

extension Optional where Wrapped == Bool {
    /// Convert optional Swift Bool to optional Kotlin Boolean
    var asKotlin: KotlinBoolean? {
        self.map { KotlinBoolean(bool: $0) }
    }
}

// MARK: - Int to KotlinInt

extension Int {
    /// Convert Swift Int to Kotlin Int
    var asKotlin: KotlinInt {
        KotlinInt(integerLiteral: self)
    }
}

extension Int32 {
    /// Convert Swift Int32 to Kotlin Int
    var asKotlin: KotlinInt {
        KotlinInt(integerLiteral: Int(self))
    }
}

extension Optional where Wrapped == Int {
    /// Convert optional Swift Int to optional Kotlin Int
    var asKotlin: KotlinInt? {
        self.map { KotlinInt(integerLiteral: $0) }
    }
}

extension Optional where Wrapped == Int32 {
    /// Convert optional Swift Int32 to optional Kotlin Int
    var asKotlin: KotlinInt? {
        self.map { KotlinInt(integerLiteral: Int($0)) }
    }
}

// MARK: - Double to KotlinDouble

extension Double {
    /// Convert Swift Double to Kotlin Double
    var asKotlin: KotlinDouble {
        KotlinDouble(double: self)
    }
}

extension Optional where Wrapped == Double {
    /// Convert optional Swift Double to optional Kotlin Double
    var asKotlin: KotlinDouble? {
        self.map { KotlinDouble(double: $0) }
    }
}

// MARK: - String to Kotlin Number Types (for form inputs)

extension String {
    /// Parse String to optional Double
    var asOptionalDouble: Double? {
        Double(self)
    }

    /// Parse String to optional KotlinDouble (for API calls)
    var asKotlinDouble: KotlinDouble? {
        Double(self).map { KotlinDouble(double: $0) }
    }

    /// Parse String to optional Int
    var asOptionalInt: Int? {
        Int(self)
    }

    /// Parse String to optional KotlinInt (for API calls)
    var asKotlinInt: KotlinInt? {
        Int(self).map { KotlinInt(integerLiteral: $0) }
    }
}

// MARK: - Int64 to KotlinLong

extension Int64 {
    /// Convert Swift Int64 to Kotlin Long
    var asKotlin: KotlinLong {
        KotlinLong(longLong: self)
    }
}

extension Optional where Wrapped == Int64 {
    /// Convert optional Swift Int64 to optional Kotlin Long
    var asKotlin: KotlinLong? {
        self.map { KotlinLong(longLong: $0) }
    }
}
