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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
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.YakAssetSyncResultVo;
import com.ruoyi.web.modules.industryservice.support.IotSyncSupport.SyncQuery;
import com.ruoyi.web.modules.industryservice.support.ThirdPartyIotEarTagClient;

@ExtendWith(MockitoExtension.class)
@DisplayName("YakEarTagSyncService")
class YakEarTagSyncServiceTest
{
    @Mock
    private ThirdPartyIotEarTagClient thirdPartyIotEarTagClient;

    @Mock
    private YakEarTagSyncTxService yakEarTagSyncTxService;

    @InjectMocks
    private YakEarTagSyncService service;

    @Test
    @DisplayName("stub 全量同步")
    void syncIncremental_full()
    {
        com.ruoyi.web.modules.industryservice.domain.dto.OpenEarTagDto dto =
                new com.ruoyi.web.modules.industryservice.domain.dto.OpenEarTagDto();
        dto.setId(1L);
        dto.setEarTagNumber("YAK1");
        dto.setReportTime("2026-05-20 10:00:00");
        when(thirdPartyIotEarTagClient.fetchIncremental(null, null, null))
                .thenReturn(java.util.Collections.singletonList(dto));
        when(yakEarTagSyncTxService.persistEarTag(any(), any())).thenReturn(true);

        YakAssetSyncResultVo result = service.syncIncremental(SyncQuery.fullSync());
        assertEquals(1, result.getInsertCount());
    }
}
