package com.starry.admin.modules.clerk.module.enums;

import cn.hutool.core.util.StrUtil;

/**
 * 员工状态【1：是陪聊，0：不是陪聊】
 */
public enum ClerkRoleStatus {
    CLERK("1"),
    NON_CLERK("0");

    private final String code;

    ClerkRoleStatus(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public boolean matches(String value) {
        return StrUtil.equals(code, value);
    }

    public boolean isClerk() {
        return this == CLERK;
    }

    public static ClerkRoleStatus fromCode(String value) {
        if (CLERK.matches(value)) {
            return CLERK;
        }
        if (NON_CLERK.matches(value)) {
            return NON_CLERK;
        }
        return NON_CLERK;
    }

    public static boolean isClerk(String value) {
        return fromCode(value).isClerk();
    }

    public static boolean transitionedToNonClerk(String newValue, String originalValue) {
        if (StrUtil.isBlank(newValue)) {
            return false;
        }
        return !isClerk(newValue) && isClerk(originalValue);
    }
}
