package com.reyun.saas.common.constants;

import org.springframework.util.StringUtils;

/**
 * @author: hanzepeng
 * @Date: 2022/02/10/10:52
 * @Description: 用户来源枚举类型
 */
public enum  UserSourceEnumType {

    SEARCH_ENGINE(1,"search_engine","搜索引擎"),
    EMAIL_PUSH(2,"email_push","邮件推送"),
    SOCIAL_MEDIA(3,"social_media","社交媒体"),
    ZHIHU(4,"zhihu","知乎问答"),
    PROMOTE_CAMPAIGN(5,"promote_campaign","推广活动"),
    SALES(6,"sales","商务沟通")
    ;


    private Integer key;
    private String code;
    private String value;

    UserSourceEnumType(Integer key,String code,String value){
        this.key = key;
        this.code = code;
        this.value = value;
    }

    public Integer getKey() {
        return key;
    }

    public void setKey(Integer key) {
        this.key = key;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    /**
     * 根据code获取枚举
     * @param code code
     * @return 目标枚举
     */
    public static UserSourceEnumType getEnumByCode(String code){
        if(StringUtils.isEmpty(code)){
            return null;
        }
        UserSourceEnumType[] values = UserSourceEnumType.values();

        UserSourceEnumType result = null;
        for (UserSourceEnumType value : values) {
            if (value.getCode().equals(code)) {
                result =  value;
                break;
            }
        }
        return result;
    }

    /**
     * 根据key获取枚举
     */
    public static UserSourceEnumType getEnumBykey(Integer key){
        if(key == null){
            return null;
        }
        UserSourceEnumType[] values = UserSourceEnumType.values();

        UserSourceEnumType result = null;
        for (UserSourceEnumType value : values) {
            if (value.getKey().equals(key)) {
                result =  value;
                break;
            }
        }
        return result;
    }


}
