
package cn.orionsec.ops.constant.app;

import cn.orionsec.ops.constant.Const;
import lombok.AllArgsConstructor;
import lombok.Getter;


@AllArgsConstructor
@Getter
public enum RepositoryTokenType {

    /**
     * github
     * <p>
     * username: ''
     */
    GITHUB(10, Const.GITHUB),

    /**
     * gitee
     * <p>
     * username: username
     */
    GITEE(20, Const.GITEE),

    /**
     * gitlab
     * <p>
     * username oauth
     */
    GITLAB(30, Const.GITLAB),

    ;

    private final Integer type;

    private final String label;

    public static RepositoryTokenType of(Integer type) {
        if (type == null) {
            return null;
        }
        for (RepositoryTokenType value : values()) {
            if (value.type.equals(type)) {
                return value;
            }
        }
        return null;
    }

    public static RepositoryTokenType of(String label) {
        if (label == null) {
            return null;
        }
        for (RepositoryTokenType value : values()) {
            if (value.label.equals(label.toLowerCase())) {
                return value;
            }
        }
        return null;
    }

}
