package com.cool.store.enums.point;

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

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

    SHOP_STAGE_1(ShopStageEnum.SHOP_STAGE_1, 10, "选址", 12),
    SHOP_STAGE_2(ShopStageEnum.SHOP_STAGE_1, 20, "上传租赁合同", 14),
    SHOP_STAGE_3(ShopStageEnum.SHOP_STAGE_2, 30, "系统建店", 19),
    SHOP_STAGE_4(ShopStageEnum.SHOP_STAGE_2, 40, "证照办理", 24),
    SHOP_STAGE_5(ShopStageEnum.SHOP_STAGE_2, 50, "员工招聘", 23),
    SHOP_STAGE_6(ShopStageEnum.SHOP_STAGE_2, 60, "加盟商/员工培训", 30),
    SHOP_STAGE_7(ShopStageEnum.SHOP_STAGE_2, 70, "缴纳加盟费/保证金", 1),
    SHOP_STAGE_8(ShopStageEnum.SHOP_STAGE_2, 80, "加盟合同签约", 4),
    SHOP_STAGE_9(ShopStageEnum.SHOP_STAGE_2, 90, "设计阶段", 21),
    SHOP_STAGE_10(ShopStageEnum.SHOP_STAGE_2, 100, "装修款", 24),
    SHOP_STAGE_11(ShopStageEnum.SHOP_STAGE_2, 110, "施工阶段", 31),
    SHOP_STAGE_12(ShopStageEnum.SHOP_STAGE_2, 120, "三方验收", 32),
    SHOP_STAGE_13(ShopStageEnum.SHOP_STAGE_2, 130, "视觉验收", 32),
    SHOP_STAGE_14(ShopStageEnum.SHOP_STAGE_2, 140, "开业运营方案", 23),
    SHOP_STAGE_15(ShopStageEnum.SHOP_STAGE_2, 150, "首批订货清单", 20),
    SHOP_STAGE_16(ShopStageEnum.SHOP_STAGE_3, 160, "开业验收", null),
    SHOP_STAGE_17(ShopStageEnum.SHOP_STAGE_4, 170, "新店开业", null),
    ;

    //阶段
    private ShopStageEnum shopStageEnum;

    //子阶段
    private Integer shopSubStage;

    //子阶段名称
    private String shopSubStageName;

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

    ShopSubStageEnum(ShopStageEnum shopStageEnum, Integer shopSubStage, String shopSubStageName, Integer planCompleteDays) {
        this.shopStageEnum = shopStageEnum;
        this.shopSubStage = shopSubStage;
        this.shopSubStageName = shopSubStageName;
        this.planCompleteDays = planCompleteDays;
    }

    public static List<ShopSubStageEnum> getShopStageEnum(Integer shopStage) {
        List<ShopSubStageEnum> resultList = new ArrayList<>();
        for (ShopSubStageEnum shopStageEnum : ShopSubStageEnum.values()) {
            if (shopStageEnum.getShopStageEnum().getShopStage().equals(shopStage)) {
                resultList.add(shopStageEnum);
            }
        }
        return resultList;
    }

    public ShopStageEnum getShopStageEnum() {
        return shopStageEnum;
    }

    public Integer getShopSubStage() {
        return shopSubStage;
    }

    public String getShopSubStageName() {
        return shopSubStageName;
    }

    public Integer getPlanCompleteDays() {
        return planCompleteDays;
    }

    /**
     * 获取各阶段的初始状态
     * @return
     */
    public ShopSubStageStatusEnum getInitStatus() {
        switch (this){
            case SHOP_STAGE_1:
                return ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_10;
            case SHOP_STAGE_5:
                return ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_50;
            case SHOP_STAGE_7:
                return ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_70;
            case SHOP_STAGE_2:
            case SHOP_STAGE_3:
            case SHOP_STAGE_4:
            case SHOP_STAGE_6:
            case SHOP_STAGE_8:
            case SHOP_STAGE_9:
            case SHOP_STAGE_10:
            case SHOP_STAGE_11:
            case SHOP_STAGE_12:
            case SHOP_STAGE_13:
            case SHOP_STAGE_14:
            case SHOP_STAGE_15:
            case SHOP_STAGE_16:
            case SHOP_STAGE_17:
                return ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_00;
            default:
                return null;
        }
    }

    public static Integer getSelectStageMaxDays() {
        return Math.max(ShopSubStageEnum.SHOP_STAGE_1.getPlanCompleteDays(), ShopSubStageEnum.SHOP_STAGE_2.getPlanCompleteDays());

    }

    public String getPlanCompleteTime(LocalDate planCompleteTime, LocalDate planSelectPointCompleteDate) {
        switch (this){
            case SHOP_STAGE_1:
            case SHOP_STAGE_2:
            case SHOP_STAGE_5:
            case SHOP_STAGE_6:
            case SHOP_STAGE_7:
            case SHOP_STAGE_8:
                return planCompleteTime.plusDays(getPlanCompleteDays()).toString();
            case SHOP_STAGE_3:
            case SHOP_STAGE_4:
            case SHOP_STAGE_9:
            case SHOP_STAGE_10:
            case SHOP_STAGE_11:
            case SHOP_STAGE_12:
            case SHOP_STAGE_13:
            case SHOP_STAGE_14:
            case SHOP_STAGE_15:
                return planSelectPointCompleteDate.plusDays(getPlanCompleteDays()).toString();
            default:
                return null;
        }
    }

    public static ShopSubStageEnum getByShopSubStage(Integer shopSubStage) {
        if(Objects.isNull(shopSubStage)){
            return null;
        }
        for (ShopSubStageEnum value : ShopSubStageEnum.values()) {
            if (value.getShopSubStage().equals(shopSubStage)) {
                return value;
            }
        }
        return null;
    }

}
