package com.leanowtech.bloge.book.practices;

import com.leanowtech.bloge.core.catalog.CapabilityEffect;
import com.leanowtech.bloge.core.catalog.Determinism;
import com.leanowtech.bloge.core.catalog.annotation.BlogeFunction;
import com.leanowtech.bloge.core.catalog.annotation.BlogeFunctionLibrary;
import java.util.Locale;

@BlogeFunctionLibrary(callablePrefix = "loanText", effect = CapabilityEffect.PURE,
        determinism = Determinism.DETERMINISTIC)
public final class LoanTextFunctions {
    private LoanTextFunctions() {}

    /**
     * Normalizes an explicit policy code without consulting process locale.
     * @param code non-blank code supplied by the caller
     * @return trimmed uppercase policy code using the root locale
     * @throws IllegalArgumentException if the code is null or blank
     */
    @BlogeFunction
    public static String normalizePolicyCode(String code) {
        if (code == null || code.isBlank()) {
            throw new IllegalArgumentException("policy code must not be blank");
        }
        return code.trim().toUpperCase(Locale.ROOT);
    }
}
