package com.cool.store.enums.close;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: ShopStageEnum
 * @Description:店铺阶段
 * @date 2024-04-10 17:34
 */
public enum CloseStoreSubStageEnum {

    CLOSE_STORE_SUB_STAGE_10(CloseStoreStageEnum.CLOSE_STORE_STAGE_1, 10, "关店所需材料上交", 1),
    CLOSE_STORE_SUB_STAGE_20(CloseStoreStageEnum.CLOSE_STORE_STAGE_2, 20, "账号关闭", 2),
    CLOSE_STORE_SUB_STAGE_30(CloseStoreStageEnum.CLOSE_STORE_STAGE_3, 30, "押金退款", 3),
    CLOSE_STORE_SUB_STAGE_40(CloseStoreStageEnum.CLOSE_STORE_STAGE_3, 40, "货款退款", 3),
    ;

    /**
     * 阶段
     */
    private CloseStoreStageEnum closeStoreStageEnum;

    /**
     * 子阶段
     */
    private Integer closeStoreSubStage;

    /**
     * 子阶段名称
     */
    private String closeStoreSubStageName;

    /**
     * 计划完成天数
     */
    private Integer planCompleteDays;

    CloseStoreSubStageEnum(CloseStoreStageEnum closeStoreStageEnum, Integer closeStoreSubStage, String closeStoreSubStageName, Integer planCompleteDays) {
        this.closeStoreStageEnum = closeStoreStageEnum;
        this.closeStoreSubStage = closeStoreSubStage;
        this.closeStoreSubStageName = closeStoreSubStageName;
        this.planCompleteDays = planCompleteDays;
    }


    public static List<CloseStoreSubStageEnum> getShopStageEnum(Integer closeStoreStage) {
        List<CloseStoreSubStageEnum> resultList = new ArrayList<>();
        for (CloseStoreSubStageEnum closeStoreSubStageEnum : CloseStoreSubStageEnum.values()) {
            if (closeStoreSubStageEnum.getCloseStoreStageEnum().getCloseStoreStage().equals(closeStoreStage)) {
                resultList.add(closeStoreSubStageEnum);
            }
        }
        return resultList;
    }

    public CloseStoreStageEnum getCloseStoreStageEnum() {
        return closeStoreStageEnum;
    }

    public Integer getCloseStoreSubStage() {
        return closeStoreSubStage;
    }

    public String getCloseStoreSubStageName() {
        return closeStoreSubStageName;
    }

    public Integer getPlanCompleteDays() {
        return planCompleteDays;
    }

    /**
     * 获取各阶段的初始状态
     *
     * @return
     */
    public CloseStoreSubStageStatusEnum getInitStatus() {
        switch (this) {
            case CLOSE_STORE_SUB_STAGE_10:
                return CloseStoreSubStageStatusEnum.CLOSE_STORE_SUB_STAGE_STATUS_10;
            case CLOSE_STORE_SUB_STAGE_20:
            case CLOSE_STORE_SUB_STAGE_30:
            case CLOSE_STORE_SUB_STAGE_40:
                return CloseStoreSubStageStatusEnum.CLOSE_STORE_SUB_STAGE_STATUS_00;
            default:
                return null;
        }
    }


    public String getPlanCompleteTime(LocalDate planCompleteTime) {
        switch (this) {
            default:
                return planCompleteTime.plusDays(getPlanCompleteDays()).toString();
        }
    }

    /**
     * 获取下一个开启的子阶段
     */
    public static List<CloseStoreSubStageEnum> getNextSubStage(CloseStoreSubStageEnum currentSubStage) {
        switch (currentSubStage) {
            case CLOSE_STORE_SUB_STAGE_10:
                return Arrays.asList(CLOSE_STORE_SUB_STAGE_20, CLOSE_STORE_SUB_STAGE_30, CLOSE_STORE_SUB_STAGE_40);
            default:
                return null;
        }
    }

    public static CloseStoreSubStageEnum getSubStageByStage(Integer subStage) {
        for (CloseStoreSubStageEnum value : CloseStoreSubStageEnum.values()) {
            if (value.getCloseStoreSubStage().equals(subStage)) {
                return value;
            }
        }
        return null;
    }

    public static String getSubStageNameBySubStage(Integer subStage) {
        for (CloseStoreSubStageEnum value : CloseStoreSubStageEnum.values()) {
            if (value.getCloseStoreSubStage().equals(subStage)) {
                return value.getCloseStoreSubStageName();
            }
        }
        return null;
    }
}
