package com.ga.batch.settlement.domain;

import com.ga.common.system.SystemConfigService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.math.BigDecimal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

/**
 * US-C 환수채권 연체이자 계산 검증.
 */
@ExtendWith(MockitoExtension.class)
class ClawbackInterestCalculatorTest {

    @Mock SystemConfigService configService;

    @Test
    @DisplayName("이자율 0(기본값)이면 적립 0 — 안전 폴백")
    void zero_rate_no_interest() {
        when(configService.getDecimal(eq("CLAWBACK_OVERDUE_INTEREST_RATE"), any(BigDecimal.class)))
                .thenReturn(BigDecimal.ZERO);
        ClawbackInterestCalculator calc = new ClawbackInterestCalculator(configService);

        assertThat(calc.monthlyInterest(new BigDecimal("1000000"))).isEqualByComparingTo("0");
    }

    @Test
    @DisplayName("연 12% → 월 1% — 잔액 1,000,000 의 1개월 연체이자 = 10,000")
    void twelve_percent_monthly() {
        when(configService.getDecimal(eq("CLAWBACK_OVERDUE_INTEREST_RATE"), any(BigDecimal.class)))
                .thenReturn(new BigDecimal("12"));
        ClawbackInterestCalculator calc = new ClawbackInterestCalculator(configService);

        // 1,000,000 × 12 / 1200 = 10,000
        assertThat(calc.monthlyInterest(new BigDecimal("1000000"))).isEqualByComparingTo("10000");
    }

    @Test
    @DisplayName("잔액 0/null 이면 이자 0")
    void zero_balance_no_interest() {
        when(configService.getDecimal(eq("CLAWBACK_OVERDUE_INTEREST_RATE"), any(BigDecimal.class)))
                .thenReturn(new BigDecimal("12"));
        ClawbackInterestCalculator calc = new ClawbackInterestCalculator(configService);

        assertThat(calc.monthlyInterest(BigDecimal.ZERO)).isEqualByComparingTo("0");
        assertThat(calc.monthlyInterest(null)).isEqualByComparingTo("0");
    }
}
