package com.gingersoft.gsa.cloud.order.bean.request;

import com.gingersoft.gsa.cloud.order.bean.discount.CouponDiscountBean;
import com.gingersoft.gsa.cloud.order.bean.discount.MemberWalletCoupon;
import com.gingersoft.gsa.cloud.order.billItem.DiscountItem;
import com.gingersoft.gsa.cloud.order.contract.OrderDiscountType;
import com.gingersoft.gsa.cloud.order.discount.MemberCouponDiscount;
import com.gingersoft.gsa.cloud.order.discount.MemberLevelDiscount;
import com.gingersoft.gsa.cloud.order.discount.MemberWalletCouponDiscount;
import com.gingersoft.gsa.cloud.order.discount.MultyDiscount;
import com.gingersoft.gsa.cloud.order.discount.NomalDiscount;

import lombok.Data;

/**
 * @author : bin
 * @create date: 2020-11-11
 * @update date: 2020-11-11
 * @description:
 */
@Data
public class OrderDiscountRequest {

    /**
     * {@link com.gingersoft.gsa.cloud.order.contract.OrderDiscountType}
     * 0#餐廳折扣
     * 1#會員折扣
     * 2#优惠券折扣
     */
    private byte type;
    /**
     * 折扣ID
     */
    private Long discountId;
    /**
     * 會員折扣ID
     */
    private Long memberId;
    /**
     * 會員折扣比例
     */
    private Integer memberDiscountRate;
    /**
     * 折扣金額
     */
    private Double discountAmount;
    /**
     * 是否计算服务费
     */
    private int scAble;

    public static OrderDiscountRequest orderDiscountTransRequest(DiscountItem discount) {
        OrderDiscountRequest request = new OrderDiscountRequest();
        request.setType(OrderDiscountType.BILL_DISCOUNT);
        if (discount.getDiscount() != null) {
            NomalDiscount discount1 = (NomalDiscount) discount.getDiscount();
            request.setDiscountId(discount1.getDiscount().getId());
        }
        request.setDiscountAmount(discount.getMoney());
        request.setScAble(0);
        return request;
    }

    public static OrderDiscountRequest memberDiscountTransRequest(DiscountItem discount) {
        OrderDiscountRequest request = new OrderDiscountRequest();
        request.setType(OrderDiscountType.MEMBER_DISCOUNT);
        if (discount.getDiscount() != null) {
            MemberLevelDiscount memberDiscount = (MemberLevelDiscount) discount.getDiscount();
            request.setMemberId(memberDiscount.getMemberDiscount().getId());
//                request.setMemberDiscountRate((int) memberDiscount.getDiscount().getDiscount_value());
        }
        request.setDiscountAmount(discount.getMoney());
        request.setScAble(0);
        return request;
    }

    public static OrderDiscountRequest couponDiscountTransRequest(DiscountItem discount) {
        OrderDiscountRequest request = new OrderDiscountRequest();
        request.setType(OrderDiscountType.COUPON_DISCOUNT);

        final MultyDiscount multyDiscount = discount.getDiscount();
        if (multyDiscount != null) {
            if (multyDiscount instanceof MemberWalletCouponDiscount) {
                MemberWalletCouponDiscount walletCouponDiscount = (MemberWalletCouponDiscount) multyDiscount;
                final MemberWalletCoupon walletCoupon = walletCouponDiscount.getWalletCoupon();
                request.setDiscountId(walletCoupon.getCouponId());
                request.setMemberDiscountRate(walletCoupon.getDiscount());
//                request.setDiscountAmount(walletCoupon.getAmount());
            } else if (multyDiscount instanceof MemberCouponDiscount) {
                MemberCouponDiscount memberCouponDiscount = (MemberCouponDiscount) multyDiscount;
                final CouponDiscountBean couponDiscount = memberCouponDiscount.getCouponDiscount();
                request.setDiscountId(couponDiscount.getId());
                request.setMemberDiscountRate(couponDiscount.getDiscount());
//                request.setDiscountAmount(couponDiscount.getAmount());
            }
        }
        request.setDiscountAmount(discount.getMoney());
        request.setScAble(0);
        return request;
    }
}
