package com.yiqi.order.domain.dto;

import com.yiqi.common.enums.GoodsType;
import com.yiqi.common.enums.OrderType;
import com.yiqi.common.enums.SourceType;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.bean.BeanUtils;
import com.yiqi.order.domain.*;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @author xiaohei
 * @date 2024/1/2
 */
@Data
public class PayOrderAppDTO extends PayOrderDTO{
    /**
     * 充值订单
     * @param orderRecharge
     * @return
     */
    public static PayOrderAppDTO buildRechargeOrderPayData(OrderRecharge orderRecharge, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        payOrderAppDTO.setStoreId(orderRecharge.getStoreId());
        payOrderAppDTO.setOrderNo(orderRecharge.getOrderNo());
        payOrderAppDTO.setPayAmount(orderRecharge.getPayAmount());
        payOrderAppDTO.setSubjectTitle(OrderType.recharge.getInfo());
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(orderRecharge.getCreateTime(), 5));
        payOrderAppDTO.setPayType(orderRecharge.getPayType());
        return payOrderAppDTO;
    }

    /**
     * 商品订单
     * @param orderGoods
     * @return
     */
    public static PayOrderAppDTO buildGoodsOrderPayData(OrderGoods orderGoods, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        payOrderAppDTO.setOrderNo(orderGoods.getOrderNo());
        payOrderAppDTO.setPayAmount(orderGoods.getPayAmount());
        if(orderGoods.getSourceType().equals(SourceType.STORE.getCode())){
            payOrderAppDTO.setStoreId(orderGoods.getOrgId());
        }
        if (GoodsType.LIFE_SERVICE.getCode().equals(orderGoods.getGoodsType())){
            payOrderAppDTO.setSubjectTitle(OrderType.life.getInfo());
        }else if (GoodsType.CAR.getCode().equals(orderGoods.getGoodsType())){
            payOrderAppDTO.setSubjectTitle(OrderType.car.getInfo());
        }else {
            payOrderAppDTO.setSubjectTitle(OrderType.goods.getInfo());
        }
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(orderGoods.getCreateTime(), 5));
        payOrderAppDTO.setPayType(orderGoods.getPayType());
        return payOrderAppDTO;
    }

    /**
     * 商品订单
     * @param orderGoods
     * @return
     */
    public static PayOrderAppDTO buildGoodsOrderPayDataByCombine(OrderGoods orderGoods, BigDecimal payAmount, String payType, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        payOrderAppDTO.setOrderNo(orderGoods.getOrderNo());
        payOrderAppDTO.setPayAmount(payAmount);
        if(orderGoods.getSourceType().equals(SourceType.STORE.getCode())){
            payOrderAppDTO.setStoreId(orderGoods.getOrgId());
        }
        if (GoodsType.LIFE_SERVICE.getCode().equals(orderGoods.getGoodsType())){
            payOrderAppDTO.setSubjectTitle(OrderType.life.getInfo());
        }else if (GoodsType.CAR.getCode().equals(orderGoods.getGoodsType())){
            payOrderAppDTO.setSubjectTitle(OrderType.car.getInfo());
        }else {
            payOrderAppDTO.setSubjectTitle(OrderType.goods.getInfo());
        }
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(orderGoods.getCreateTime(), 5));
        payOrderAppDTO.setPayType(payType);
        return payOrderAppDTO;
    }

    /**
     * 配送费订单
     * @param orderClothDeliveryAddress
     * @return
     */
    public static PayOrderAppDTO buildDeliveryOrderPayData(OrderClothDeliveryAddress orderClothDeliveryAddress, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        payOrderAppDTO.setOrderNo(orderClothDeliveryAddress.getOrderNo());
        payOrderAppDTO.setPayAmount(orderClothDeliveryAddress.getDeliveryAmount());
        payOrderAppDTO.setPayType(orderClothDeliveryAddress.getPayType());
        payOrderAppDTO.setSubjectTitle(OrderType.delivery.getInfo());
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(orderClothDeliveryAddress.getCreateTime(), 5));
        return payOrderAppDTO;
    }

    /**
     * 配送费订单
     * @param orderActivity
     * @return
     */
    public static PayOrderAppDTO buildActivityOrderPayData(OrderActivity orderActivity, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        if(orderActivity.getSourceType().equals(SourceType.STORE.getCode())){
            payOrderAppDTO.setStoreId(orderActivity.getOrgId());
        }
        payOrderAppDTO.setOrderNo(orderActivity.getOrderNo());
        payOrderAppDTO.setPayAmount(orderActivity.getPayAmount());
        payOrderAppDTO.setPayType(orderActivity.getPayType());
        payOrderAppDTO.setSubjectTitle(OrderType.activity.getInfo());
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(orderActivity.getCreateTime(), 5));
        return payOrderAppDTO;
    }

    /**
     * 配送费订单
     * @param orderCloth
     * @return
     */
    public static PayOrderAppDTO buildClothOrderPayData(OrderCloth orderCloth, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        if(orderCloth.getSourceType().equals(SourceType.STORE.getCode())){
            payOrderAppDTO.setStoreId(orderCloth.getOrgId());
        }
        payOrderAppDTO.setOrderNo(orderCloth.getOrderNo());
        payOrderAppDTO.setPayAmount(orderCloth.getPayAmount());
        payOrderAppDTO.setPayType(orderCloth.getPayType());
        payOrderAppDTO.setSubjectTitle(OrderType.cloth.getInfo());
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(DateUtils.getNowDate(), 5));
        return payOrderAppDTO;
    }

    /**
     * 配送费订单
     * @param orderCloth
     * @return
     */
    public static PayOrderAppDTO buildClothOrderPayDataByCombine(OrderCloth orderCloth, BigDecimal payAmount, String payType, String platform){
        PayOrderAppDTO payOrderAppDTO = new PayOrderAppDTO();
        payOrderAppDTO.setPlatform(platform);
        if(orderCloth.getSourceType().equals(SourceType.STORE.getCode())){
            payOrderAppDTO.setStoreId(orderCloth.getOrgId());
        }
        payOrderAppDTO.setOrderNo(orderCloth.getOrderNo());
        payOrderAppDTO.setPayAmount(payAmount);
        payOrderAppDTO.setPayType(payType);
        payOrderAppDTO.setSubjectTitle(OrderType.cloth.getInfo());
        payOrderAppDTO.setExpireTime(DateUtils.addMinutes(DateUtils.getNowDate(), 5));
        return payOrderAppDTO;
    }
}
