import XCTest
@testable import PortfolioJournal

final class CurrencyFormatterTests: XCTestCase {

    func testParseUserInput_withDotDecimalAndThreeDigits_keepsDecimal() {
        let value = CurrencyFormatter.parseUserInput("533.595", currencySymbol: "€")
        XCTAssertEqual(value, Decimal(string: "533.595"))
    }

    func testParseUserInput_withCommaDecimalAndThreeDigits_keepsDecimal() {
        let value = CurrencyFormatter.parseUserInput("533,595", currencySymbol: "€")
        XCTAssertEqual(value, Decimal(string: "533.595"))
    }

    func testParseUserInput_withGroupedThousands_preservesIntegerValue() {
        let dotGrouped = CurrencyFormatter.parseUserInput("1.234.567", currencySymbol: "€")
        let commaGrouped = CurrencyFormatter.parseUserInput("1,234,567", currencySymbol: "$")

        XCTAssertEqual(dotGrouped, Decimal(string: "1234567"))
        XCTAssertEqual(commaGrouped, Decimal(string: "1234567"))
    }

    func testParseUserInput_withMixedSeparators_parsesDecimal() {
        let eu = CurrencyFormatter.parseUserInput("1.234,56", currencySymbol: "€")
        let us = CurrencyFormatter.parseUserInput("1,234.56", currencySymbol: "$")

        XCTAssertEqual(eu, Decimal(string: "1234.56"))
        XCTAssertEqual(us, Decimal(string: "1234.56"))
    }

    func testParseUserInput_withSmallDecimalValue_keepsPrecision() {
        let value = CurrencyFormatter.parseUserInput("0.000123", currencySymbol: "$")
        XCTAssertEqual(value, Decimal(string: "0.000123"))
    }
}
