package com.zioinfo.kintex.settlement;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * F084 옥션 수수료 산정 단위테스트 — 요율(룰셋/기본 5%)·부가세 10%·총액 산식 고정.
 */
class AuctionFeeTest {

    @Test
    void appliesRulesetRate() {
        // 낙찰가 8,400,000 × 5% = 420,000, VAT 42,000, total 462,000
        AuctionFee.Fee f = AuctionFee.compute(8_400_000L, 5.0);
        assertEquals(8_400_000L, f.base());
        assertEquals(5.0, f.ratePercent());
        assertEquals(420_000L, f.fee());
        assertEquals(42_000L, f.vat());
        assertEquals(462_000L, f.total());
    }

    @Test
    void fallsBackToDefaultRateWhenNullOrNonPositive() {
        AuctionFee.Fee f1 = AuctionFee.compute(10_000_000L, null);
        assertEquals(AuctionFee.DEFAULT_FEE_RATE_PERCENT, f1.ratePercent());
        assertEquals(500_000L, f1.fee());   // 5%
        assertEquals(550_000L, f1.total());

        AuctionFee.Fee f2 = AuctionFee.compute(10_000_000L, 0.0);
        assertEquals(AuctionFee.DEFAULT_FEE_RATE_PERCENT, f2.ratePercent());
    }

    @Test
    void customRateRoundsHalfUp() {
        // 3,333,333 × 3% = 99,999.99 → round 100,000
        AuctionFee.Fee f = AuctionFee.compute(3_333_333L, 3.0);
        assertEquals(100_000L, f.fee());
        assertEquals(10_000L, f.vat());
    }

    @Test
    void zeroWhenNonPositiveWinningTotal() {
        AuctionFee.Fee f = AuctionFee.compute(0L, 5.0);
        assertEquals(0L, f.fee());
        assertEquals(0L, f.vat());
        assertEquals(0L, f.total());
    }
}
