package de.effigenix.domain.masterdata.article;

import de.effigenix.shared.common.Result;

public record ArticleName(String value) {

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

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