package com.starry.admin.modules.order.service.impl;

import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.order.module.dto.OrderAmountBreakdown;
import com.starry.admin.modules.order.module.dto.OrderCreationContext;
import com.starry.admin.modules.order.module.dto.OrderPlacementCommand;
import com.starry.admin.modules.order.module.dto.PaymentInfo;

class OtherOrderPlacementStrategy extends AbstractOrderPlacementStrategy {

    OtherOrderPlacementStrategy(OrderLifecycleServiceImpl service) {
        super(service);
    }

    @Override
    protected OrderAmountBreakdown handlePricing(OrderPlacementCommand command, OrderCreationContext context) {
        PaymentInfo info = context.getPaymentInfo();
        if (info == null) {
            throw new CustomException("支付信息不能为空");
        }
        context.setPaymentInfo(PaymentInfo.builder()
                .orderMoney(service.normalizeMoney(info.getOrderMoney()))
                .discountAmount(service.normalizeMoney(info.getDiscountAmount()))
                .finalAmount(service.normalizeMoney(info.getFinalAmount()))
                .couponIds(info.getCouponIds())
                .payMethod(info.getPayMethod())
                .paymentSource(info.getPaymentSource())
                .build());
        return null;
    }
}
