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

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

import java.util.Collections;
import java.util.Date;
import java.util.List;

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.industryservice.domain.BizPasture;
import com.ruoyi.web.modules.industryservice.domain.vo.YakAssetSyncResultVo;
import com.ruoyi.web.modules.industryservice.mapper.BizPastureMapper;
import com.ruoyi.web.modules.industryservice.service.PastureSyncService;

@ExtendWith(MockitoExtension.class)
@DisplayName("牧场管理 Service")
class BizPastureServiceImplTest
{
    @Mock
    private BizPastureMapper bizPastureMapper;

    @Mock
    private PastureSyncService pastureSyncService;

    @InjectMocks
    private BizPastureServiceImpl service;

    @Test
    @DisplayName("按 id 查询")
    void selectById()
    {
        BizPasture row = new BizPasture();
        row.setId(1L);
        when(bizPastureMapper.selectBizPastureById(1L)).thenReturn(row);
        assertEquals(1L, service.selectBizPastureById(1L).getId());
    }

    @Test
    @DisplayName("列表空结果返回空集合")
    void listEmpty()
    {
        when(bizPastureMapper.selectBizPastureList(any())).thenReturn(null);
        List<BizPasture> list = service.selectBizPastureList(new BizPasture());
        assertNotNull(list);
        assertEquals(0, list.size());
    }

    @Test
    @DisplayName("列表有数据")
    void listRows()
    {
        when(bizPastureMapper.selectBizPastureList(any())).thenReturn(Collections.singletonList(new BizPasture()));
        assertEquals(1, service.selectBizPastureList(new BizPasture()).size());
    }

    @Test
    @DisplayName("委托同步服务")
    void syncFromThirdParty()
    {
        YakAssetSyncResultVo vo = new YakAssetSyncResultVo();
        vo.setInsertCount(1);
        vo.setSyncTime(new Date());
        when(pastureSyncService.syncFromThirdParty()).thenReturn(vo);
        YakAssetSyncResultVo result = service.syncFromThirdParty();
        assertEquals(1, result.getInsertCount());
        verify(pastureSyncService).syncFromThirdParty();
    }
}
