package com.ga.api.service.commission;

import com.ga.core.mapper.commission.HqSettleItemMapper;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
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.Mockito.when;

@ExtendWith(MockitoExtension.class)
class HqSettleServiceTest {

    @Mock HqSettleItemMapper itemMapper;

    @InjectMocks HqSettleService service;

    @Test
    @DisplayName("summary: profit = income - expense (3,000,000 - 1,200,000 = 1,800,000)")
    void summary_profitCalc() {
        when(itemMapper.sumByMonthAndType("202506", "INCOME")).thenReturn(new BigDecimal("3000000"));
        when(itemMapper.sumByMonthAndType("202506", "EXPENSE")).thenReturn(new BigDecimal("1200000"));

        HqSettleService.HqSummaryResp result = service.summary("202506");

        assertThat(result.getIncome()).isEqualByComparingTo("3000000");
        assertThat(result.getExpense()).isEqualByComparingTo("1200000");
        assertThat(result.getProfit()).isEqualByComparingTo("1800000");
        assertThat(result.getSettleMonth()).isEqualTo("202506");
    }

    @Test
    @DisplayName("summary: income/expense null이면 0으로 처리 → profit = 0")
    void summary_nullHandling() {
        when(itemMapper.sumByMonthAndType("202506", "INCOME")).thenReturn(null);
        when(itemMapper.sumByMonthAndType("202506", "EXPENSE")).thenReturn(null);

        HqSettleService.HqSummaryResp result = service.summary("202506");

        assertThat(result.getProfit()).isEqualByComparingTo("0");
    }
}
