package com.mzh.library.entity;

import java.util.Locale;

public enum BookStatus {
    AVAILABLE("available", "可借"),
    UNAVAILABLE("unavailable", "不可借"),
    ARCHIVED("archived", "已归档");

    private final String code;
    private final String displayName;

    BookStatus(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    public String getCode() {
        return code;
    }

    public String getDisplayName() {
        return displayName;
    }

    public static BookStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Book status is required");
        }

        String normalized = code.trim().toLowerCase(Locale.ROOT);
        for (BookStatus status : values()) {
            if (status.code.equals(normalized)) {
                return status;
            }
        }

        throw new IllegalArgumentException("Unsupported book status: " + code);
    }
}
