package com.cool.store.enums.close;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: ShopStageStatusEnum
 * @Description:店铺阶段状态
 * @date 2024-04-10 17:34
 */
public enum CloseStoreSubStageStatusEnum {

    CLOSE_STORE_SUB_STAGE_STATUS_00(null, -100, "未开始", Boolean.FALSE),

    /**
     * 材料上传
     */
    CLOSE_STORE_SUB_STAGE_STATUS_10(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 100, "待内勤填写地址", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_15(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 110, "未提交", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_16(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 120, "待运营顾问审核", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_17(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 130, "运营顾问审批驳回", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_18(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 140, "待内勤审核", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_19(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 150, "内勤审批驳回", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_20(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_10, 160, "已完成", Boolean.TRUE),

    /**
     * 账号关闭
     */
    CLOSE_STORE_SUB_STAGE_STATUS_25(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_20, 200, "进行中", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_30(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_20, 210, "已完成", Boolean.TRUE),

    /**
     * 押金退款
     */
    CLOSE_STORE_SUB_STAGE_STATUS_35(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_30, 310, "待退款", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_40(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_30, 330, "已完成", Boolean.TRUE),

    /**
     * 货款退款
     */
    CLOSE_STORE_SUB_STAGE_STATUS_45(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_40, 410, "待退款", Boolean.FALSE),
    CLOSE_STORE_SUB_STAGE_STATUS_50(CloseStoreSubStageEnum.CLOSE_STORE_SUB_STAGE_40, 430, "已完成", Boolean.TRUE),

    ;

    private CloseStoreSubStageEnum closeStoreSubStageEnum;

    private Integer shopSubStageStatus;

    private String shopSubStageStatusName;

    private boolean isTerminated;


    CloseStoreSubStageStatusEnum(CloseStoreSubStageEnum closeStoreSubStageEnum, Integer shopSubStageStatus, String shopSubStageStatusName, Boolean isTerminated) {
        this.closeStoreSubStageEnum = closeStoreSubStageEnum;
        this.shopSubStageStatus = shopSubStageStatus;
        this.shopSubStageStatusName = shopSubStageStatusName;
        this.isTerminated = isTerminated;
    }

    public static List<CloseStoreSubStageStatusEnum> getCloseStoreSubStageStatusEnum(CloseStoreSubStageEnum closeStoreSubStageEnum) {
        List<CloseStoreSubStageStatusEnum> resultList = new ArrayList<>();
        for (CloseStoreSubStageStatusEnum stageStatusEnum : CloseStoreSubStageStatusEnum.values()) {
            if (Objects.nonNull(stageStatusEnum.getCloseStoreSubStageEnum()) && stageStatusEnum.getCloseStoreSubStageEnum().equals(closeStoreSubStageEnum)) {
                resultList.add(stageStatusEnum);
            }
        }
        return resultList;
    }

    public CloseStoreSubStageEnum getCloseStoreSubStageEnum() {
        return closeStoreSubStageEnum;
    }

    public Integer getShopSubStageStatus() {
        return shopSubStageStatus;
    }

    public String getShopSubStageStatusName() {
        return shopSubStageStatusName;
    }

    public String getShopSubStageName() {
        return closeStoreSubStageEnum.getCloseStoreSubStageName();
    }

    public boolean isTerminated() {
        return isTerminated;
    }

    public static CloseStoreSubStageStatusEnum getCloseStoreSubStageStatusEnum(Integer CloseStoreSubStageStatus) {
        for (CloseStoreSubStageStatusEnum storeSubStageStatusEnum : CloseStoreSubStageStatusEnum.values()) {
            if (Objects.nonNull(storeSubStageStatusEnum.getShopSubStageStatus()) && storeSubStageStatusEnum.getShopSubStageStatus().equals(CloseStoreSubStageStatus)) {
                return storeSubStageStatusEnum;
            }
        }
        return CLOSE_STORE_SUB_STAGE_STATUS_00;
    }

    public static CloseStoreSubStageStatusEnum getByStatus(Integer shopSubStageStatus) {
        for (CloseStoreSubStageStatusEnum statusEnum : CloseStoreSubStageStatusEnum.values()) {
            if (statusEnum.getShopSubStageStatus().equals(shopSubStageStatus)) {
                return statusEnum;
            }
        }
        return null;
    }

    /**
     * 获取下一个阶段状态
     * @param current 当前阶段状态
     * @return 阶段状态
     */
    public static CloseStoreSubStageStatusEnum getNextStageStatus(CloseStoreSubStageStatusEnum current) {
        switch (current) {
            case CLOSE_STORE_SUB_STAGE_STATUS_10:
                return CLOSE_STORE_SUB_STAGE_STATUS_15;
            case CLOSE_STORE_SUB_STAGE_STATUS_15:
            case CLOSE_STORE_SUB_STAGE_STATUS_17:
                return CLOSE_STORE_SUB_STAGE_STATUS_16;
            case CLOSE_STORE_SUB_STAGE_STATUS_16:
            case CLOSE_STORE_SUB_STAGE_STATUS_19:
                return CLOSE_STORE_SUB_STAGE_STATUS_18;
            case CLOSE_STORE_SUB_STAGE_STATUS_18:
                return CLOSE_STORE_SUB_STAGE_STATUS_20;
            case CLOSE_STORE_SUB_STAGE_STATUS_25:
                return CLOSE_STORE_SUB_STAGE_STATUS_30;
            case CLOSE_STORE_SUB_STAGE_STATUS_35:
                return CLOSE_STORE_SUB_STAGE_STATUS_40;
            case CLOSE_STORE_SUB_STAGE_STATUS_45:
                return CLOSE_STORE_SUB_STAGE_STATUS_50;
            default:
                return null;
        }
    }

    /**
     * 获取子流程的开始阶段状态
     * @param subStage 子流程
     * @return 阶段状态
     */
    public static CloseStoreSubStageStatusEnum getOpenStageStatus(CloseStoreSubStageEnum subStage) {
        switch (subStage) {
            case CLOSE_STORE_SUB_STAGE_10:
                return CLOSE_STORE_SUB_STAGE_STATUS_10;
            case CLOSE_STORE_SUB_STAGE_20:
                return CLOSE_STORE_SUB_STAGE_STATUS_25;
            case CLOSE_STORE_SUB_STAGE_30:
                return CLOSE_STORE_SUB_STAGE_STATUS_35;
            case CLOSE_STORE_SUB_STAGE_40:
                return CLOSE_STORE_SUB_STAGE_STATUS_45;
            default:
                return null;
        }
    }

    public static String getStatusNameByStatus(Integer status) {
        for (CloseStoreSubStageStatusEnum statusEnum : CloseStoreSubStageStatusEnum.values()) {
            if (statusEnum.getShopSubStageStatus().equals(status)) {
                return statusEnum.getShopSubStageStatusName();
            }
        }
        return null;
    }
}
