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

import com.jeesharp.business.modules.trade.api.TradeOrderFacadeApi;
import com.jeesharp.business.modules.trade.application.TradeOrderApplicationService;
import com.jeesharp.business.modules.trade.dto.TradeOrderCreateDTO;
import com.jeesharp.business.modules.trade.entity.TradeOrder;
import com.jeesharp.business.modules.trade.entity.TradeOrderItem;
import com.jeesharp.business.modules.trade.service.TradeOrderItemService;
import com.jeesharp.business.modules.trade.vo.TradeOrderInfoVO;
import com.jeesharp.business.modules.trade.vo.TradeOrderQueryVO;
import com.jeesharp.framework.pojo.Page;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * {@link TradeOrderFacadeApi} 实现，委托 {@link TradeOrderApplicationService} 完成统一单编排。
 *
 * @author jeesharp
 * @since 2026-06-08
 */
@Service
@AllArgsConstructor
public class TradeOrderFacadeApiImpl implements TradeOrderFacadeApi {

    private final TradeOrderApplicationService tradeOrderApplicationService;
    private final TradeOrderItemService tradeOrderItemService;

    @Override
    public String createPendingPayOrder(TradeOrderCreateDTO dto) {
        TradeOrderInfoVO vo = tradeOrderApplicationService.createPendingPayOrder(dto);
        return vo != null ? vo.getId() : null;
    }

    @Override
    public void markPaid(String orderId, String payOrderId, String payChannel) {
        tradeOrderApplicationService.markPaid(orderId, payOrderId, payChannel);
    }

    @Override
    public void markCancelled(String orderId) {
        tradeOrderApplicationService.markCancelled(orderId);
    }

    @Override
    public void cancelPending(String orderId) {
        tradeOrderApplicationService.cancelPending(orderId);
    }

    @Override
    public void markClosed(String orderId) {
        tradeOrderApplicationService.markClosed(orderId);
    }

    @Override
    public void markFulfilling(String orderId) {
        tradeOrderApplicationService.markFulfilling(orderId);
    }

    @Override
    public void markFulfilled(String orderId) {
        tradeOrderApplicationService.markFulfilled(orderId);
    }

    @Override
    public TradeOrder get(String id) {
        return tradeOrderApplicationService.get(id);
    }

    @Override
    public Page<TradeOrder> findPage(Page<TradeOrder> page, TradeOrderQueryVO query) {
        return tradeOrderApplicationService.findPage(page, query);
    }

    @Override
    public List<TradeOrderItem> findItemsByTradeOrderIds(List<String> tradeOrderIds) {
        return tradeOrderItemService.findByTradeOrderIds(tradeOrderIds);
    }
}
