package de.effigenix.infrastructure.masterdata.web.exception;

import de.effigenix.domain.masterdata.article.ArticleError;
import de.effigenix.domain.masterdata.customer.CustomerError;
import de.effigenix.domain.masterdata.productcategory.ProductCategoryError;
import de.effigenix.domain.masterdata.supplier.SupplierError;

public final class MasterDataErrorHttpStatusMapper {

    private MasterDataErrorHttpStatusMapper() {}

    public static int toHttpStatus(ArticleError error) {
        return switch (error) {
            case ArticleError.ArticleNotFound e -> 404;
            case ArticleError.SalesUnitNotFound e -> 404;
            case ArticleError.ArticleNumberAlreadyExists e -> 409;
            case ArticleError.DuplicateSalesUnitType e -> 409;
            case ArticleError.MinimumSalesUnitRequired e -> 400;
            case ArticleError.InvalidPriceModelCombination e -> 400;
            case ArticleError.InvalidPrice e -> 400;
            case ArticleError.ValidationFailure e -> 400;
            case ArticleError.Unauthorized e -> 403;
            case ArticleError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(SupplierError error) {
        return switch (error) {
            case SupplierError.SupplierNotFound e -> 404;
            case SupplierError.CertificateNotFound e -> 404;
            case SupplierError.SupplierNameAlreadyExists e -> 409;
            case SupplierError.InvalidRating e -> 400;
            case SupplierError.ValidationFailure e -> 400;
            case SupplierError.Unauthorized e -> 403;
            case SupplierError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(ProductCategoryError error) {
        return switch (error) {
            case ProductCategoryError.CategoryNotFound e -> 404;
            case ProductCategoryError.CategoryNameAlreadyExists e -> 409;
            case ProductCategoryError.CategoryInUse e -> 409;
            case ProductCategoryError.InvalidCategoryName e -> 400;
            case ProductCategoryError.ValidationFailure e -> 400;
            case ProductCategoryError.Unauthorized e -> 403;
            case ProductCategoryError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(CustomerError error) {
        return switch (error) {
            case CustomerError.CustomerNotFound e -> 404;
            case CustomerError.CustomerNameAlreadyExists e -> 409;
            case CustomerError.FrameContractNotAllowed e -> 400;
            case CustomerError.InvalidFrameContract e -> 400;
            case CustomerError.DuplicateContractLineItem e -> 409;
            case CustomerError.ValidationFailure e -> 400;
            case CustomerError.Unauthorized e -> 403;
            case CustomerError.RepositoryFailure e -> 500;
        };
    }
}
