package com.yc.ship.module.trade.enums;


import com.yc.ship.framework.common.core.IntArrayValuable;
import com.yc.ship.framework.common.util.object.ObjectUtils;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

/**
 * 券码 - 状态
 *
 */
@RequiredArgsConstructor
@Getter
public enum VoucherStatusEnum implements IntArrayValuable {
    CANCELED(-2, "已取消"),
    FAIL(-1, "下单失败"),//供应商订单下单失败
    INIT(0, "初始状态"),
    UNUSED(1, "待使用"),
    TOOK(2, "已取票"),
    VERIFIED(3, "已核销"),
    REFUNDING(4, "退款中"),
    REFUND(5, "已退款"),
    OVERDUE_VERIFIED(6, "逾期核销"),
    EXPIRED(7, "已过期"),
    PART_VERIFIED(8, "部分核销"),
    PART_REFUND(9, "部分退款"),
    ;



    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(VoucherStatusEnum::getStatus).toArray();

    /**
     * 状态值
     */
    private final Integer status;
    /**
     * 状态名
     */
    private final String name;

    @Override
    public int[] array() {
        return ARRAYS;
    }

    /**
     * 能否核销(门票)
     * @param status 状态
     * @return boolean
     */
    public static boolean canCheck(Integer status) {
        return UNUSED.getStatus().equals(status)
                || TOOK.getStatus().equals(status)
                || PART_VERIFIED.getStatus().equals(status)
                || VERIFIED.getStatus().equals(status)
                || PART_REFUND.getStatus().equals(status)
                || REFUND.getStatus().equals(status);
    }

    /**
     * 能否核销(子票)
     * @param status 状态
     * @return boolean
     */
    public static boolean canCheckForSub(Integer status) {
        return UNUSED.getStatus().equals(status) || TOOK.getStatus().equals(status)
                || REFUNDING.getStatus().equals(status)  || PART_VERIFIED.getStatus().equals(status) || VERIFIED.getStatus().equals(status);
    }

    /**
     * 是否取票状态
     * @param status 状态
     * @return boolean
     */
    public static boolean hasTook(Integer status) {
        return TOOK.getStatus().equals(status);
    }

    /**
     * 是否是未使用状态 (出行状态用)
     * @param status 状态
     * @return boolean
     */
    public static boolean isUnused(Integer status) {
        return UNUSED.getStatus().equals(status) || TOOK.getStatus().equals(status) || EXPIRED.getStatus().equals(status);
    }

    /**
     * 是否是已核销状态 (出行状态用)
     * @param status 状态
     * @return boolean
     */
    public static boolean isChecked(Integer status) {
        return VERIFIED.getStatus().equals(status) || OVERDUE_VERIFIED.getStatus().equals(status);
    }

    public static boolean isRefundForce(Integer status) {
        return  ObjectUtils.equalsAny(status,VoucherStatusEnum.UNUSED.getStatus(),VoucherStatusEnum.TOOK.getStatus()
                ,VoucherStatusEnum.VERIFIED.getStatus(),VoucherStatusEnum.OVERDUE_VERIFIED.getStatus(),VoucherStatusEnum.PART_VERIFIED.getStatus());
    }

    public static boolean isRefundNormal(Integer status) {
        return  ObjectUtils.equalsAny(status,VoucherStatusEnum.UNUSED.getStatus(),VoucherStatusEnum.TOOK.getStatus());
    }
}
