package com.ruoyi.web.modules.trading.service.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.math.BigDecimal;
import java.util.Collections;

import com.ruoyi.web.modules.trading.domain.dto.AppDistributorTradeSummaryDto;
import com.ruoyi.web.modules.trading.domain.vo.AppDistributorHomeDashboardVo;
import com.ruoyi.web.modules.trading.mapper.AppDistributorTradeMapper;
import com.ruoyi.web.modules.trading.support.AppDistributorHomeRules;
import com.ruoyi.web.modules.trading.support.AppDistributorSessionSupport;
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;

@ExtendWith(MockitoExtension.class)
@DisplayName("AppDistributorHomeServiceImpl")
class AppDistributorHomeServiceImplTest
{
    @Mock
    private AppDistributorSessionSupport appDistributorSessionSupport;

    @Mock
    private AppDistributorTradeMapper appDistributorTradeMapper;

    @InjectMocks
    private AppDistributorHomeServiceImpl service;

    @Test
    @DisplayName("今日看板")
    void loadDashboardToday()
    {
        when(appDistributorSessionSupport.requireDistributorId()).thenReturn(8L);
        AppDistributorTradeSummaryDto summary = new AppDistributorTradeSummaryDto();
        summary.setOrderCount(2L);
        summary.setCompletedCount(1L);
        summary.setTotalAmount(new BigDecimal("36800"));
        summary.setTotalHeads(3L);
        summary.setSupplierCount(1L);
        when(appDistributorTradeMapper.selectTradeSummary(any(), any(), any())).thenReturn(summary);
        when(appDistributorTradeMapper.selectHourlyAmountTrend(any(), any(), any()))
                .thenReturn(Collections.emptyList());

        AppDistributorHomeDashboardVo vo = service.loadDashboard(AppDistributorHomeRules.RANGE_TODAY);
        assertEquals(AppDistributorHomeRules.RANGE_TODAY, vo.getRange());
        assertEquals("今日", vo.getRangeName());
        assertEquals(AppDistributorHomeRules.TREND_GRANULARITY_HOUR, vo.getTrendGranularity());
        assertEquals(2L, vo.getSummary().getOrderCount());
        assertEquals(1L, vo.getSummary().getSupplierCount());
        assertEquals(24, vo.getAmountTrend().size());
    }
}
