package com.ruoyi.web.modules.trading.support;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collections;
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.trading.mapper.BizEntryIsolationMapper;
import com.ruoyi.web.modules.trading.mapper.BizIsolationPatrolMapper;
import com.ruoyi.web.modules.trading.mapper.BizMarketEntryEarTagMapper;

@ExtendWith(MockitoExtension.class)
@DisplayName("MarketEntryEarTagResolver")
class MarketEntryEarTagResolverTest
{
    @Mock
    private BizEntryIsolationMapper bizEntryIsolationMapper;

    @Mock
    private BizIsolationPatrolMapper bizIsolationPatrolMapper;

    @Mock
    private BizMarketEntryEarTagMapper bizMarketEntryEarTagMapper;

    @InjectMocks
    private MarketEntryEarTagResolver resolver;

    @Test
    @DisplayName("supplierEarTags：A-B")
    void listSupplierEarTagOptions()
    {
        when(bizEntryIsolationMapper.selectEndedMainEarTagRowsBySupplier(1L))
                .thenReturn(Collections.singletonList("E101,E102,E103"));
        when(bizIsolationPatrolMapper.selectSickDeadEarTagRows())
                .thenReturn(Collections.singletonList("E102"));
        assertEquals(Arrays.asList("E101", "E103"), resolver.listSupplierEarTagOptions(1L));
    }

    @Test
    @DisplayName("保存校验：(A-B)-C")
    void listEligible()
    {
        when(bizEntryIsolationMapper.selectEndedMainEarTagRowsBySupplier(1L))
                .thenReturn(Collections.singletonList("E101,E102,E103"));
        when(bizIsolationPatrolMapper.selectSickDeadEarTagRows())
                .thenReturn(Collections.singletonList("E102"));
        when(bizMarketEntryEarTagMapper.selectOccupiedEarTags(null))
                .thenReturn(Collections.singletonList("E101"));
        assertEquals(Collections.singletonList("E103"), resolver.listEligible(1L, null));
    }

    @Test
    @DisplayName("占用来自子表")
    void loadOccupied()
    {
        when(bizMarketEntryEarTagMapper.selectOccupiedEarTags(null))
                .thenReturn(Arrays.asList("E101", "E201"));
        assertTrue(resolver.loadOccupiedEarTags(null).contains("E101"));
        assertFalse(resolver.loadOccupiedEarTags(null).contains("E103"));
    }
}
