package de.effigenix.domain.masterdata.customer;

import de.effigenix.domain.masterdata.article.ArticleId;

public sealed interface CustomerError {

    String code();
    String message();

    record CustomerNotFound(CustomerId id) implements CustomerError {
        @Override public String code() { return "CUSTOMER_NOT_FOUND"; }
        @Override public String message() { return "Customer with ID '" + id.value() + "' not found"; }
    }

    record CustomerNameAlreadyExists(String name) implements CustomerError {
        @Override public String code() { return "CUSTOMER_NAME_EXISTS"; }
        @Override public String message() { return "Customer name '" + name + "' already exists"; }
    }

    record FrameContractNotAllowed() implements CustomerError {
        @Override public String code() { return "FRAME_CONTRACT_NOT_ALLOWED"; }
        @Override public String message() { return "Frame contracts are only allowed for B2B customers"; }
    }

    record InvalidFrameContract(String reason) implements CustomerError {
        @Override public String code() { return "INVALID_FRAME_CONTRACT"; }
        @Override public String message() { return "Invalid frame contract: " + reason; }
    }

    record DuplicateContractLineItem(ArticleId articleId) implements CustomerError {
        @Override public String code() { return "DUPLICATE_LINE_ITEM"; }
        @Override public String message() { return "Duplicate line item for article '" + articleId.value() + "'"; }
    }

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

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

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