package com.cool.store.enums.order;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
public enum StoreOrderStatusEnum {

    DRAFT(0, "草稿"),
    WAIT_CONFIRM(5, "待立规确认"),
    DEVICE_CONFIRM(6, "待采购设备确认"),
    INVEST_MANAGER_CONFIRM(7, "待加盟商确认"),
    FINANCIAL_CONFIRM(8, "待内勤确认"),
    WAIT_ADJUST(10, "待调整"),
    WAIT_PAY(15, "待支付"),
    PART_OF_WAIT_PAY(17, "部分支付"),
    PAID(20, "已支付"),
    PAY_FAIL(22, "支付失败"),
    CLOSED(25, "已关闭");

    private final Integer code;
    private final String desc;

    StoreOrderStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, StoreOrderStatusEnum> MAP = Arrays.stream(values())
            .collect(Collectors.toMap(StoreOrderStatusEnum::getCode, Function.identity(), (a, b) -> a));

    public static StoreOrderStatusEnum of(Integer code) {
        return MAP.get(code);
    }



    /**
     * 待审核状态
     * @param code
     * @return
     */
    public static boolean approve(Integer code) {
        return WAIT_CONFIRM.getCode().equals(code) || INVEST_MANAGER_CONFIRM.getCode().equals(code) || DEVICE_CONFIRM.getCode().equals(code);
    }

    /**
     * 后台管理订单 只有立规确认或者设备确认的时候可以修改
     * @param code
     * @return
     */
    public static boolean managerOrder(Integer code) {
        return WAIT_CONFIRM.getCode().equals(code) ||  DEVICE_CONFIRM.getCode().equals(code);
    }
}
