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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import java.util.Collections;
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.stock.constant.StockConstants;
import com.ruoyi.web.modules.stock.dto.StockLogQuery;
import com.ruoyi.web.modules.stock.mapper.BizStockLogMapper;
import com.ruoyi.web.modules.stock.service.impl.StockLogServiceImpl;
import com.ruoyi.web.modules.stock.support.StockSupport;
import com.ruoyi.web.modules.stock.vo.StockLogListRowVO;

@ExtendWith(MockitoExtension.class)
class StockLogServiceImplTest
{
    private static final Long SHOP_ID = 101L;

    private static final Long GOODS_ID = 1001L;

    @Mock
    private BizStockLogMapper stockLogMapper;

    @Mock
    private StockSupport stockSupport;

    @InjectMocks
    private StockLogServiceImpl stockLogService;

    @Test
    void selectList_enrichesReasonText()
    {
        StockLogListRowVO row = new StockLogListRowVO();
        row.setChangeReason(StockConstants.REASON_ORDER_DEDUCT);
        when(stockLogMapper.selectList(eq(SHOP_ID), any(StockLogQuery.class)))
                .thenReturn(Collections.singletonList(row));
        when(stockSupport.changeReasonText(StockConstants.REASON_ORDER_DEDUCT)).thenReturn("下单扣减库存");

        StockLogListRowVO result = stockLogService.selectList(SHOP_ID, new StockLogQuery()).get(0);

        assertEquals("下单扣减库存", result.getChangeReasonText());
    }

    @Test
    void selectByGoodsId_enrichesReasonText()
    {
        StockLogListRowVO row = new StockLogListRowVO();
        row.setChangeReason(StockConstants.REASON_PURCHASE_IN);
        when(stockLogMapper.selectByGoodsId(SHOP_ID, GOODS_ID)).thenReturn(Collections.singletonList(row));
        when(stockSupport.changeReasonText(StockConstants.REASON_PURCHASE_IN)).thenReturn("采购入库");

        StockLogListRowVO result = stockLogService.selectByGoodsId(SHOP_ID, GOODS_ID).get(0);

        assertEquals("采购入库", result.getChangeReasonText());
    }
}
