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

import cn.hutool.core.util.StrUtil;

/**
 * 在职状态（1：在职，0：离职）
 */
public enum OnboardingStatus {
    ACTIVE("1"),
    OFFBOARDED("0");

    private final String code;

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

    public String getCode() {
        return code;
    }

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

    public boolean isActive() {
        return this == ACTIVE;
    }

    public static OnboardingStatus fromCode(String value) {
        if (ACTIVE.matches(value)) {
            return ACTIVE;
        }
        if (OFFBOARDED.matches(value)) {
            return OFFBOARDED;
        }
        return ACTIVE;
    }

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

    public static boolean isOffboarded(String value) {
        return !isActive(value);
    }

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