package com.ruoyi.ss.transactionBill.domain.enums;

import com.ruoyi.common.enums.UserType;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author wjh
 * 2024/3/12
 */
@AllArgsConstructor
@Getter
public enum TransactionBillStatus {

    UNPAID("1", "未支付"),
    SUCCESS("2", "支付成功"),
    REFUNDED("3", "已退款"),
    CANCELED("4", "已取消（用户）"),
    SYS_CANCELED("5", "已取消（系统）"),
    PAYING("6", "支付中"),
    REFUNDING("7", "退款中"),
    UNPAID_DEPOSIT("8", "押金未支付"),
    SUCCESS_DEPOSIT("9", "押金已支付"),

    WITHDRAW_APPROVING("11", "提现申请中"),
    WITHDRAW_PASSED("12", "提现申请通过"),
    WITHDRAW_REJECTED("13", "提现申请拒绝"),
    WITHDRAW_SUCCESS("14", "提现已打款"),
    WITHDRAW_FAIL("15", "提现打款失败"),
    WITHDRAW_PAYING("16", "提现打款中");

    private final String status;
    private final String name;

    public static TransactionBillStatus parse(String status) {
        for (TransactionBillStatus obj : TransactionBillStatus.values()) {
            if (Objects.equals(obj.getStatus(), status)) {
                return obj;
            }
        }
        throw new RuntimeException("不存在值为" + status + "的枚举类型");
    }

    public static List<String> asList(TransactionBillStatus ...statuses) {
        return Arrays.stream(statuses).map(TransactionBillStatus::getStatus).collect(Collectors.toList());
    }

    /**
     * 判断状态是否为取消状态
     * @param status 状态
     */
    public static boolean isCancel(String status) {
        return asList(CANCELED, SYS_CANCELED).contains(status);
    }


    /**
     * 限额统计的提现状态
     */
    public static List<String> countOfLimit() {
        return asList(WITHDRAW_SUCCESS, WITHDRAW_APPROVING, WITHDRAW_PASSED, WITHDRAW_PAYING);
    }

    /**
     * 可以结束的状态
     */
    public static List<String> canClose() {
        return asList(SUCCESS, SUCCESS_DEPOSIT);
    }

    /**
     * 已支付过的订单状态
     */
    public static List<String> payedOrder() {
        return asList(SUCCESS, REFUNDED, REFUNDING);
    }

    /**
     * 已收取服务费的状态
     */
    public static List<String> serviceIncome() {
        return asList(SUCCESS, REFUNDED, REFUNDING, WITHDRAW_SUCCESS);
    }

    /**
     * 产生收入的状态
     */
    public static List<String> income() {
        return asList(SUCCESS, REFUNDING, REFUNDED);
    }
}
