package com.mzh.library.entity;

import java.util.Locale;

public enum BorrowRecordStatus {
    ACTIVE("active", "借阅中"),
    RETURNED("returned", "已归还");

    private final String code;
    private final String displayName;

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

    public String getCode() {
        return code;
    }

    public String getDisplayName() {
        return displayName;
    }

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

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

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