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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collections;
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 com.ruoyi.web.modules.prosperity.ProsperityAchievementTestSamples;
import com.ruoyi.web.modules.prosperity.domain.vo.AchievementAnnualReportVo;
import com.ruoyi.web.modules.prosperity.domain.vo.AchievementReportYearsVo;
import com.ruoyi.web.modules.prosperity.mapper.BizCommonProsperityAchievementMapper;

/**
 * GTFY-NB-UT-013、015
 */
@ExtendWith(MockitoExtension.class)
@DisplayName("AchievementReportServiceImpl")
class AchievementReportServiceImplTest
{

    @Mock
    private BizCommonProsperityAchievementMapper achievementMapper;

    @InjectMocks
    private AchievementReportServiceImpl service;

    @Test
    @DisplayName("GTFY-NB-UT-013 可选年份列表")
    void ut013_listYears()
    {
        when(achievementMapper.selectDistinctStatYears()).thenReturn(Arrays.asList("2026", "2024"));
        AchievementReportYearsVo vo = service.listAvailableYears();
        assertEquals(2, vo.getYears().size());
        assertEquals(2026, vo.getYears().get(0).intValue());
    }

    @Test
    @DisplayName("年度报告查询")
    void getAnnualReport()
    {
        when(achievementMapper.selectByStatYear("2026"))
                .thenReturn(Collections.singletonList(ProsperityAchievementTestSamples.sample()));
        AchievementAnnualReportVo report = service.getAnnualReport("2026");
        assertEquals(2026, report.getStatYear().intValue());
        assertTrue(report.getHasData());
        verify(achievementMapper).selectByStatYear("2026");
    }

    @Test
    @DisplayName("全年无数据")
    void getAnnualReportEmpty()
    {
        when(achievementMapper.selectByStatYear("2099")).thenReturn(Collections.emptyList());
        AchievementAnnualReportVo report = service.getAnnualReport("2099");
        assertFalse(report.getHasData());
    }
}
