package com.cool.store.enums;

import java.util.Objects;

/**
 * @Author: WangShuo
 * @Date: 2025/01/08/下午5:51
 * @Version 1.0
 * @注释:
 */
public enum JoinModeEnum {
    FRANCHISE_DEPARTMENT(1,"加盟部加盟店"),
    FRANCHISE_COMPANIES(2,"加盟公司加盟店"),
    OWN_STORE(3,"加盟公司自有店"),
    STRONG_FRANCHISE(4,"强加盟"),
    DIRECT_SALES_TO_JOINING(5,"老店转加盟"),
    AFFILIATES(6,"联营店"),
    FLAGSHIP_STORE(7,"直营店"),
    ;
    private int code;
    private String desc;
    private JoinModeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    public int getCode() {
        return code;
    }
    public String getDesc() {
        return desc;
    }
    public static String getByCode(Integer code) {
        if (code == null){
            return null;
        }
        for (JoinModeEnum e : JoinModeEnum.values()) {
            if (e.getCode() == code) {
                return e.desc;
            }
        }
        return null;
    }
    /**
     * 是否是加盟部加盟店或者联营店 如果不是 返回false
     */
    public static boolean isFranchise(Integer code) {
        return code == FRANCHISE_DEPARTMENT.code || code == AFFILIATES.code;
    }

    public static JoinModeEnum getModelByCode(Integer code) {
        for (JoinModeEnum e : JoinModeEnum.values()) {
            if (e.getCode() == code) {
                return e;
            }
        }
        return null;
    }

    public static String getDescByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        for (JoinModeEnum e : JoinModeEnum.values()) {
            if (e.getCode() == code) {
                return e.desc;
            }
        }
        return null;
    }
}
