package com.aegis.emergency.dispatch.constant;

/**
 * 任务资源使用状态枚举。
 *
 * <p>在调度任务与资源的关联流程中，资源通常经历如下状态：
 * <ul>
 *     <li>{@link #LOCKED}：已占用但尚未消耗/释放</li>
 *     <li>{@link #CONSUMED}：占用后已办理出库，等待结案或归还</li>
 *     <li>{@link #RETURNED}：已归还，库存完成回滚</li>
 *     <li>{@link #UNLOCKED}：无需使用，已直接释放锁定</li>
 * </ul>
 * </p>
 */
public enum ResourceUsageStatus {

    LOCKED("locked"),
    CONSUMED("consumed"),
    RETURNED("returned"),
    UNLOCKED("unlocked");

    private final String code;

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

    public String getCode() {
        return code;
    }

    public static ResourceUsageStatus fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (ResourceUsageStatus status : values()) {
            if (status.code.equalsIgnoreCase(code)) {
                return status;
            }
        }
        return null;
    }
}