package com.yuchen.saas.parking.api.vo.coupon;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * @author zhouhanwei
 * @create 2023/6/8 16:35
 */
@Data
public class UserPayUseCouponDetailRespVO {

    /**
     * 优惠券使用状态（1： 可使用，2：不可使用）
     */
    private Integer useFlag;

    /**
     * 使用优惠券类型（1： 车辆专属优惠券，2：用户优惠券）
     */
    private Integer useCouponUserType;

    /**
     * 优惠券列表
     */
    private List<UseCouponDetail> useCouponDetailList;


    @Data
    public static class UseCouponDetail {
        /**
         * 优惠券类型
         */
        private Integer couponType;

        /**
         * 用户使用优惠券id
         */
        private String couponRecordId;

        /**
         * 优惠券编号
         */
        private String couponCode;

        @ApiModelProperty(name = "supposeCost", value = "应付金额(单位分)")
        private Integer supposeCost;

        @ApiModelProperty(name = "discountMode", value = "优惠方式(1:限免优惠 2:全免优惠)")
        private Integer discountMode;

        @ApiModelProperty(name = "couponAmount", value = "优惠券金额(单位分)")
        private Integer couponAmount;

        @ApiModelProperty(name = "suitCondition", value = "适用条件(1:满xx元可使用 2:无门槛使用(若优惠金额大于产品金额，则该产品价格为免费))")
        private Integer suitCondition;

        @ApiModelProperty(name = "conditionAmount", value = "满xx元可使用(单位分)")
        private Integer conditionAmount;

        @ApiModelProperty(name = "discountItems", value = "优惠适用费项(1:临停费用 2:月卡充值 3:错时充值 4:管理费),多选,逗号隔开")
        private String discountItems;

        @ApiModelProperty(name = "parkingIds", value = "适用范围(停车场ID,多个逗号隔开)")
        private String parkingIds;

        @ApiModelProperty(name = "endDate", value = "优惠券有效期结束时间")
        private Date endDate;

        @ApiModelProperty(name = "receiveTime", value = "领取时间")
        private Date receiveTime;

        @ApiModelProperty(name = "payUserId", value = "payUserId")
        private String payUserId;

        @ApiModelProperty(name = "userDetailId", value = "userDetailId")
        private Long userDetailId;

        @ApiModelProperty(name = "useFlag", value = "1：可用，2：不可使用")
        private Integer useFlag;

        @ApiModelProperty(name = "noUseReason", value = "不可使用原因")
        private String noUseReason;

        @ApiModelProperty(name = "privacyProtectionFlag", value = "订单隐私保护（0：不隐藏，1：隐藏车场及时长， 2：隐藏车场）")
        private Integer privacyProtectionFlag;
    }

/*
    public static void main(String[] args) {
        List<UserPayUseCouponDetailRespVO.UseCouponDetail> couponListByPlateNo = new ArrayList<>();
        UserPayUseCouponDetailRespVO.UseCouponDetail aa= new UserPayUseCouponDetailRespVO.UseCouponDetail();
        aa.setDiscountMode(1);
        aa.setCouponAmount(1000);
        aa.setSupposeCost(52600);
        UserPayUseCouponDetailRespVO.UseCouponDetail bb= new UserPayUseCouponDetailRespVO.UseCouponDetail();
        bb.setDiscountMode(1);
        bb.setCouponAmount(50000);
        bb.setSupposeCost(52600);

        couponListByPlateNo.add(aa);
        couponListByPlateNo.add(bb);
        couponListByPlateNo.sort(new UserPayUseCouponDetailRespVO.CustomComparator());

  *//*      for (UserPayUseCouponDetailRespVO.UseCouponDetail item:
        couponListByPlateNo) {
            System.out.println
        }*//*

        System.out.println(couponListByPlateNo);
    }*/


    public static class CustomComparator implements Comparator<UseCouponDetail> {

        @Override
        public int compare(UseCouponDetail o1, UseCouponDetail o2) {

            Integer cost1=0;
            Integer cost2=0;
            if(o1.getDiscountMode()==1){
                cost1=(o1.getCouponAmount()-o1.getSupposeCost())>=0?0:o1.getCouponAmount()-o1.getSupposeCost();
            }else{
                cost1=0;
            }

            if(o2.getDiscountMode()==1){
                cost2=(o1.getCouponAmount()-o1.getSupposeCost())>=0?0:o2.getCouponAmount()-o2.getSupposeCost();
            }else{
                cost2=0;
            }

            int compareA = Integer.compare(cost1, cost2);
            if (compareA != 0) {
                return -compareA;
            }

            int compareB = o1.getEndDate().compareTo(o2.getEndDate());
            if (compareB != 0) {
                return -compareB;
            }

            int compareC =  Integer.compare(o1.getCouponAmount(), o2.getCouponAmount());
            if (compareC != 0) {
                return -compareC;
            }
            int compareD = o1.getReceiveTime().compareTo(o2.getReceiveTime());
            if (compareD != 0) {
                return -compareB;
            }

            return compareD;

        }
    }
}
