package com.jeesharp.business.modules.food.application.support;

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.food.entity.FoodMealOrder;
import com.jeesharp.business.modules.food.vo.FoodPersonalMealPayPrepareVO;
import com.jeesharp.business.modules.pay.support.VerticalPayPrepareSupport;
import org.springframework.stereotype.Component;

/**
 * 个人/企业团餐预支付 VO 组装（Application 层）。
 *
 * @author jeesharp
 * @since 2026-07-03
 */
@Component
public class FoodMealPayAssembler {

    private static final String ORDER_TYPE_COMPANY = "company";

    public FoodPersonalMealPayPrepareVO buildPrepareVo(FoodMealOrder order) {
        FoodPersonalMealPayPrepareVO vo = new FoodPersonalMealPayPrepareVO();
        String payOrderId = StrUtil.blankToDefault(order.getTradeOrderId(), "");
        vo.setOrderId(order.getId());
        vo.setOrderNo(order.getOrderNo());
        vo.setAmountFen(VerticalPayPrepareSupport.yuanToFen(order.getUserPayAmount()));
        vo.setDescription(buildDescription(order));
        vo.setTenantId(order.getTenantId());
        vo.setPayOrderId(payOrderId);
        vo.setOutTradeNo(order.getUnifiedOrderId());
        VerticalPayPrepareSupport.fillClientSignPlaceholders(vo);
        VerticalPayPrepareSupport.fillMockPrepayPackage(vo, payOrderId);
        return vo;
    }

    private static String buildDescription(FoodMealOrder order) {
        String orderNo = order.getOrderNo();
        if (ORDER_TYPE_COMPANY.equals(order.getOrderType())) {
            return "企业团餐订单" + orderNo;
        }
        return "个人订餐订单" + orderNo;
    }
}
