package de.effigenix.domain.masterdata.productcategory;

import de.effigenix.shared.common.Result;

public record CategoryName(String value) {

    public CategoryName {
        if (value == null || value.isBlank()) {
            throw new IllegalArgumentException("CategoryName must not be blank");
        }
        if (value.length() > 100) {
            throw new IllegalArgumentException("CategoryName must not exceed 100 characters");
        }
    }

    public static Result<String, CategoryName> of(String value) {
        try {
            return Result.success(new CategoryName(value));
        } catch (IllegalArgumentException e) {
            return Result.failure(e.getMessage());
        }
    }
}
