package de.effigenix.domain.masterdata.article;

import de.effigenix.shared.common.Result;

public record ArticleNumber(String value) {

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

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