package org.dromara.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.dromara.app.domain.AppSchedulingDevice;
import org.dromara.app.mapper.AppSchedulingDeviceMapper;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
@Tag("dev")
class AppSchedulingDeviceServiceImplTest {

    @Mock
    private AppSchedulingDeviceMapper mapper;

    @Test
    void findBoundDeviceNos_usesOneConstrainedQuery() {
        AppSchedulingDeviceServiceImpl service = new AppSchedulingDeviceServiceImpl(mapper);
        AppSchedulingDevice first = new AppSchedulingDevice();
        first.setDeviceNo("D01");
        AppSchedulingDevice duplicate = new AppSchedulingDevice();
        duplicate.setDeviceNo("D01");
        when(mapper.selectList(any(Wrapper.class))).thenReturn(List.of(first, duplicate));

        Set<String> result = service.findBoundDeviceNos(List.of("D01", "D02"));

        assertThat(result).containsExactly("D01");
        verify(mapper, times(1)).selectList(any(Wrapper.class));
    }
}
