package com.yiqi.recharge.domain.dto;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yiqi.common.annotation.Excel;
import com.yiqi.common.core.domain.AuthHolder;
import com.yiqi.common.enums.OrderSourceType;
import com.yiqi.common.enums.OrderType;
import com.yiqi.common.enums.SourceType;
import com.yiqi.common.enums.SysBoolType;
import com.yiqi.common.exception.ServiceException;
import com.yiqi.common.utils.SecurityUtils;
import com.yiqi.order.domain.*;
import com.yiqi.order.domain.dto.RefundBaseDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @author xiaohei
 * @date 2023/11/12
 */
@Data
public class ConsumeOrderDTO {

    /**
     * 订单类型,详见枚举OrderType
     */
    private String orderType;

    /**
     * 订单ID
     */
    private Long orderId;

    /**
     * 订单编号
     */
    private String orderNo;

    /**
     * 扣减金额
     */
    private BigDecimal amount;

    /**
     * 积分
     */
    private Integer pointAmount;

    /**
     * 客户ID
     */
    private Long appUserId;

    /**
     * 消费门店*
     */
    private Long storeId;

    /**
     * 会员卡绑定门店
     */
    private Long useBindStoreId;

    /**
     * 订单来源
     */
    private String source;

    /**
     * 支付方式
     */
    private String payType;

    private String isRefund;

    /**
     * @param orderCloth
     * @return
     */
    public static ConsumeOrderDTO buildOrderClothData(OrderCloth orderCloth) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderCloth.getPayAmount());
        consumeOrderDTO.setAppUserId(orderCloth.getAppUserId());
        consumeOrderDTO.setOrderId(orderCloth.getId());
        consumeOrderDTO.setOrderNo(orderCloth.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.cloth.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.NO.getCode());
        consumeOrderDTO.setPayType(orderCloth.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 充值订单处理余额
     *
     * @param orderRecharge
     * @return
     */
    public static ConsumeOrderDTO buildOrderRechargeData(OrderRecharge orderRecharge) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderRecharge.getPayAmount());
        consumeOrderDTO.setAppUserId(orderRecharge.getAppUserId());
        consumeOrderDTO.setOrderId(orderRecharge.getId());
        consumeOrderDTO.setOrderNo(orderRecharge.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.recharge.getCode());
        consumeOrderDTO.setUseBindStoreId(orderRecharge.getStoreId());
        consumeOrderDTO.setPointAmount(orderRecharge.getGivePointAmount());
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.NO.getCode());
        consumeOrderDTO.setPayType(orderRecharge.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 活动订单扣减余额
     *
     * @param orderActivity
     * @return
     */
    public static ConsumeOrderDTO buildOrderActivityData(OrderActivity orderActivity) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderActivity.getPayAmount());
        consumeOrderDTO.setAppUserId(orderActivity.getAppUserId());
        consumeOrderDTO.setOrderId(orderActivity.getId());
        consumeOrderDTO.setOrderNo(orderActivity.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.goods.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(orderActivity.getOrgId());
        consumeOrderDTO.setIsRefund(SysBoolType.NO.getCode());
        consumeOrderDTO.setPayType(orderActivity.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 商品订单扣减余额
     *
     * @param orderGoods
     * @return
     */
    public static ConsumeOrderDTO buildOrderGoodsData(OrderGoods orderGoods) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderGoods.getPayAmount());
        consumeOrderDTO.setAppUserId(orderGoods.getAppUserId());
        consumeOrderDTO.setOrderId(orderGoods.getId());
        consumeOrderDTO.setOrderNo(orderGoods.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.goods.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(orderGoods.getOrgId());
        consumeOrderDTO.setIsRefund(SysBoolType.NO.getCode());
        consumeOrderDTO.setPayType(orderGoods.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 配送订单扣减余额
     *
     * @param orderClothDeliveryAddress
     * @return
     */
    public static ConsumeOrderDTO buildOrderDeliveryData(OrderClothDeliveryAddress orderClothDeliveryAddress) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderClothDeliveryAddress.getDeliveryAmount());
        consumeOrderDTO.setAppUserId(orderClothDeliveryAddress.getAppUserId());
        consumeOrderDTO.setOrderId(orderClothDeliveryAddress.getId());
        consumeOrderDTO.setOrderNo(orderClothDeliveryAddress.getDeliveryOrderNo());
        consumeOrderDTO.setOrderType(OrderType.delivery.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.NO.getCode());
        consumeOrderDTO.setPayType(orderClothDeliveryAddress.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 配送订单扣减余额
     *
     * @param orderClothDeliveryAddress
     * @return
     */
    public static ConsumeOrderDTO buildOrderDeliveryData(OrderClothDeliveryAddress orderClothDeliveryAddress, Long orgId, String sourceType) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderClothDeliveryAddress.getDeliveryAmount());
        consumeOrderDTO.setAppUserId(orderClothDeliveryAddress.getAppUserId());
        consumeOrderDTO.setOrderId(orderClothDeliveryAddress.getId());
        consumeOrderDTO.setOrderNo(orderClothDeliveryAddress.getDeliveryOrderNo());
        consumeOrderDTO.setOrderType(OrderType.delivery.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(orgId);
        consumeOrderDTO.setIsRefund(SysBoolType.NO.getCode());
        consumeOrderDTO.setPayType(orderClothDeliveryAddress.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 洗衣订单退款
     *
     * @param orderCloth
     * @return
     */
    public static ConsumeOrderDTO buildOrderClothRefundData(OrderCloth orderCloth) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderCloth.getPayAmount());
        consumeOrderDTO.setAppUserId(orderCloth.getAppUserId());
        consumeOrderDTO.setOrderId(orderCloth.getId());
        consumeOrderDTO.setOrderNo(orderCloth.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.cloth.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.YES.getCode());
        consumeOrderDTO.setPayType(orderCloth.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 充值订单退款
     *
     * @param orderRecharge
     * @return
     */
    public static ConsumeOrderDTO buildOrderRechargeRefundData(OrderRecharge orderRecharge) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderRecharge.getPayAmount());
        consumeOrderDTO.setAppUserId(orderRecharge.getAppUserId());
        consumeOrderDTO.setOrderId(orderRecharge.getId());
        consumeOrderDTO.setOrderNo(orderRecharge.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.recharge.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.YES.getCode());
        consumeOrderDTO.setPayType(orderRecharge.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 商品订单退款
     *
     * @param orderGoods
     * @return
     */
    public static ConsumeOrderDTO buildOrderGoodsRefundData(OrderGoods orderGoods) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderGoods.getPayAmount());
        consumeOrderDTO.setAppUserId(orderGoods.getAppUserId());
        consumeOrderDTO.setOrderId(orderGoods.getId());
        consumeOrderDTO.setOrderNo(orderGoods.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.goods.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.YES.getCode());
        consumeOrderDTO.setPayType(orderGoods.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 配送订单退款
     *
     * @param orderClothDeliveryAddress
     * @return
     */
    public static ConsumeOrderDTO buildOrderDeliveryRefundData(OrderClothDeliveryAddress orderClothDeliveryAddress) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderClothDeliveryAddress.getDeliveryAmount());
        consumeOrderDTO.setAppUserId(orderClothDeliveryAddress.getAppUserId());
        consumeOrderDTO.setOrderId(orderClothDeliveryAddress.getId());
        consumeOrderDTO.setOrderNo(orderClothDeliveryAddress.getDeliveryOrderNo());
        consumeOrderDTO.setOrderType(OrderType.delivery.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.YES.getCode());
        consumeOrderDTO.setPayType(orderClothDeliveryAddress.getPayType());
        return consumeOrderDTO;
    }

    /**
     * 活动订单退款
     *
     * @param orderActivity
     * @return
     */
    public static ConsumeOrderDTO buildOrderActivityRefundData(OrderActivity orderActivity) {
        ConsumeOrderDTO consumeOrderDTO = new ConsumeOrderDTO();
        consumeOrderDTO.setAmount(orderActivity.getPayAmount());
        consumeOrderDTO.setAppUserId(orderActivity.getAppUserId());
        consumeOrderDTO.setOrderId(orderActivity.getId());
        consumeOrderDTO.setOrderNo(orderActivity.getOrderNo());
        consumeOrderDTO.setOrderType(OrderType.activity.getCode());
        consumeOrderDTO.setPointAmount(0);
        consumeOrderDTO.setStoreId(SecurityUtils.getLoginUser().getStoreId());
        consumeOrderDTO.setIsRefund(SysBoolType.YES.getCode());
        consumeOrderDTO.setPayType(orderActivity.getPayType());
        return consumeOrderDTO;
    }
}
