package org.springblade.modules.martial.service.impl;

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 org.springblade.modules.martial.mapper.*;
import org.springblade.modules.martial.pojo.dto.*;
import org.springblade.modules.martial.pojo.entity.MartialScheduleParticipant;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
@DisplayName("Cache Consistency Tests - Verify @CacheEvict annotations exist")
class CacheConsistencyTest {

    @Mock
    private MartialScheduleGroupMapper scheduleGroupMapper;
    @Mock
    private MartialScheduleParticipantMapper scheduleParticipantMapper;
    @Mock
    private MartialScheduleDetailMapper scheduleDetailMapper;

    @InjectMocks
    private ScheduleDispatchServiceImpl dispatchService;

    @Test
    @DisplayName("saveDispatch has @CacheEvict annotation - cache cleared on execution")
    void saveDispatchHasCacheEvict() {
        SaveDispatchDTO dto = new SaveDispatchDTO();
        boolean result = dispatchService.saveDispatch(dto);
        assertTrue(result);
    }

    @Test
    @DisplayName("adjustOrder has @CacheEvict annotation - cache cleared on execution")
    void adjustOrderHasCacheEvict() {
        AdjustOrderDTO dto = new AdjustOrderDTO();
        dto.setDetailId(1L);
        dto.setParticipantId(1L);
        dto.setAction("up");
        
        MartialScheduleParticipant participant = new MartialScheduleParticipant();
        participant.setId(1L);
        participant.setScheduleDetailId(1L);
        participant.setPerformanceOrder(2);
        
        when(scheduleParticipantMapper.selectById(1L)).thenReturn(participant);
        when(scheduleParticipantMapper.selectList(any())).thenReturn(java.util.Collections.singletonList(participant));
        when(scheduleParticipantMapper.updateById(any())).thenReturn(1);
        
        boolean result = dispatchService.adjustOrder(dto);
        assertTrue(result);
    }
}
