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

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

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.vo.LivestockFinanceSyncResultVo;
import com.ruoyi.web.modules.industryservice.domain.vo.YakAssetSyncResultVo;

@ExtendWith(MockitoExtension.class)
@DisplayName("LivestockFinanceMasterSyncService")
class LivestockFinanceMasterSyncServiceTest
{
    @Mock
    private PastureSyncService pastureSyncService;

    @Mock
    private FarmEnclosureSyncService farmEnclosureSyncService;

    @Mock
    private FarmingPlanSyncService farmingPlanSyncService;

    @Mock
    private FarmingBatchSyncService farmingBatchSyncService;

    @Mock
    private YakAssetSyncService yakAssetSyncService;

    @InjectMocks
    private LivestockFinanceMasterSyncService service;

    @Test
    @DisplayName("按顺序同步基础数据与入栏建档")
    void syncAll_inOrder()
    {
        YakAssetSyncResultVo empty = new YakAssetSyncResultVo();
        YakAssetSyncResultVo yak = new YakAssetSyncResultVo();
        yak.setInsertCount(2);
        when(pastureSyncService.syncFromThirdParty()).thenReturn(empty);
        when(farmEnclosureSyncService.syncFromThirdParty()).thenReturn(empty);
        when(farmingPlanSyncService.syncFromThirdParty()).thenReturn(empty);
        when(farmingBatchSyncService.syncFromThirdParty()).thenReturn(empty);
        when(yakAssetSyncService.syncFromThirdParty()).thenReturn(yak);

        LivestockFinanceSyncResultVo result = service.syncAll();

        assertNotNull(result.getSyncTime());
        assertEquals(2, result.getInsertCount());
        verify(pastureSyncService).syncFromThirdParty();
        verify(farmEnclosureSyncService).syncFromThirdParty();
        verify(farmingPlanSyncService).syncFromThirdParty();
        verify(farmingBatchSyncService).syncFromThirdParty();
        verify(yakAssetSyncService).syncFromThirdParty();
    }
}
