package de.effigenix.domain.masterdata.article;

import de.effigenix.domain.masterdata.Unit;

public sealed interface ArticleError {

    String code();
    String message();

    record ArticleNotFound(ArticleId id) implements ArticleError {
        @Override public String code() { return "ARTICLE_NOT_FOUND"; }
        @Override public String message() { return "Article with ID '" + id.value() + "' not found"; }
    }

    record ArticleNumberAlreadyExists(String articleNumber) implements ArticleError {
        @Override public String code() { return "ARTICLE_NUMBER_EXISTS"; }
        @Override public String message() { return "Article number '" + articleNumber + "' already exists"; }
    }

    record SalesUnitNotFound(SalesUnitId id) implements ArticleError {
        @Override public String code() { return "SALES_UNIT_NOT_FOUND"; }
        @Override public String message() { return "SalesUnit with ID '" + id.value() + "' not found"; }
    }

    record MinimumSalesUnitRequired() implements ArticleError {
        @Override public String code() { return "MINIMUM_SALES_UNIT"; }
        @Override public String message() { return "Article must have at least one SalesUnit"; }
    }

    record DuplicateSalesUnitType(Unit unit) implements ArticleError {
        @Override public String code() { return "DUPLICATE_SALES_UNIT_TYPE"; }
        @Override public String message() { return "Article already has a SalesUnit of type " + unit; }
    }

    record InvalidPriceModelCombination(String reason) implements ArticleError {
        @Override public String code() { return "INVALID_PRICE_MODEL"; }
        @Override public String message() { return "Invalid Unit/PriceModel combination: " + reason; }
    }

    record InvalidPrice(String reason) implements ArticleError {
        @Override public String code() { return "INVALID_PRICE"; }
        @Override public String message() { return "Invalid price: " + reason; }
    }

    record ValidationFailure(String message) implements ArticleError {
        @Override public String code() { return "VALIDATION_ERROR"; }
    }

    record Unauthorized(String message) implements ArticleError {
        @Override public String code() { return "UNAUTHORIZED"; }
    }

    record RepositoryFailure(String message) implements ArticleError {
        @Override public String code() { return "REPOSITORY_ERROR"; }
    }
}
