package com.jeesharp.business.modules.trade.application;

import com.jeesharp.business.modules.trade.entity.TradeOrder;
import com.jeesharp.business.modules.trade.service.TradeOrderItemService;
import com.jeesharp.business.modules.trade.service.TradeOrderService;
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * {@link TradeOrderApplicationService} 编排委托与 VO 组装单元测试（领域规则见 {@link TradeOrderService} 实现侧测试）。
 *
 * @author jeesharp
 * @since 2026-05-08
 */
@ExtendWith(MockitoExtension.class)
class TradeOrderApplicationServiceTest {

    @Mock
    private TradeOrderService tradeOrderService;

    @Mock
    private TradeOrderItemService tradeOrderItemService;

    @InjectMocks
    private TradeOrderApplicationService tradeOrderApplicationService;

    @Test
    @DisplayName("markPaid：委托领域服务")
    void markPaid_delegatesToDomainService() {
        String orderId = "order-1";
        tradeOrderApplicationService.markPaid(orderId, "pay-100", "WECHAT");
        verify(tradeOrderService).markPaid(orderId, "pay-100", "WECHAT");
    }

    @Test
    @DisplayName("cancelPending：委托领域服务")
    void cancelPending_delegatesToDomainService() {
        String orderId = "order-2";
        tradeOrderApplicationService.cancelPending(orderId);
        verify(tradeOrderService).cancelPending(orderId);
    }

    @Test
    @DisplayName("get：委托领域服务")
    void get_delegatesToService() {
        when(tradeOrderService.get("x")).thenReturn(null);
        assertNull(tradeOrderApplicationService.get("x"));
    }

    @Test
    @DisplayName("toInfoVo：null 返回 null")
    void toInfoVo_whenNull_returnsNull() {
        assertNull(tradeOrderApplicationService.toInfoVo(null));
    }

    @Test
    @DisplayName("toInfoVo：映射主键与业务单号")
    void toInfoVo_mapsIdAndOrderNo() {
        TradeOrder order = new TradeOrder();
        order.setId("id-1");
        order.setOrderNo("UTO1");
        var vo = tradeOrderApplicationService.toInfoVo(order);
        assertEquals("id-1", vo.getId());
        assertEquals("UTO1", vo.getOrderNo());
    }
}
