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

import de.effigenix.domain.inventory.InventoryCountError;
import de.effigenix.domain.inventory.StockMovementError;
import de.effigenix.domain.inventory.StorageLocationError;
import de.effigenix.domain.inventory.StockError;

public final class InventoryErrorHttpStatusMapper {

    private InventoryErrorHttpStatusMapper() {}

    public static int toHttpStatus(StorageLocationError error) {
        return switch (error) {
            case StorageLocationError.StorageLocationNotFound e -> 404;
            case StorageLocationError.NameAlreadyExists e -> 409;
            case StorageLocationError.StockExistsAtLocation e -> 409;
            case StorageLocationError.AlreadyActive e -> 409;
            case StorageLocationError.AlreadyInactive e -> 409;
            case StorageLocationError.InvalidName e -> 400;
            case StorageLocationError.InvalidTemperatureRange e -> 400;
            case StorageLocationError.InvalidStorageType e -> 400;
            case StorageLocationError.Unauthorized e -> 403;
            case StorageLocationError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(StockError error) {
        return switch (error) {
            case StockError.StockNotFound e -> 404;
            case StockError.BatchNotFound e -> 404;
            case StockError.ReservationNotFound e -> 404;
            case StockError.DuplicateStock e -> 409;
            case StockError.DuplicateBatchReference e -> 409;
            case StockError.NegativeStockNotAllowed e -> 409;
            case StockError.BatchNotAvailable e -> 409;
            case StockError.BatchAlreadyBlocked e -> 409;
            case StockError.BatchNotBlocked e -> 409;
            case StockError.InsufficientStock e -> 409;
            case StockError.InvalidMinimumLevel e -> 400;
            case StockError.InvalidMinimumShelfLife e -> 400;
            case StockError.InvalidArticleId e -> 400;
            case StockError.InvalidStorageLocationId e -> 400;
            case StockError.InvalidBatchReference e -> 400;
            case StockError.InvalidQuantity e -> 400;
            case StockError.InvalidExpiryDate e -> 400;
            case StockError.InvalidFilterCombination e -> 400;
            case StockError.InvalidReferenceType e -> 400;
            case StockError.InvalidReferenceId e -> 400;
            case StockError.InvalidReservationPriority e -> 400;
            case StockError.Unauthorized e -> 403;
            case StockError.MovementCreationFailed e -> 500;
            case StockError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(InventoryCountError error) {
        return switch (error) {
            case InventoryCountError.InventoryCountNotFound e -> 404;
            case InventoryCountError.InvalidCountItemId e -> 400;
            case InventoryCountError.CountItemNotFound e -> 404;
            case InventoryCountError.ActiveCountExists e -> 409;
            case InventoryCountError.DuplicateArticle e -> 409;
            case InventoryCountError.InvalidStatusTransition e -> 409;
            case InventoryCountError.NoCountItems e -> 409;
            case InventoryCountError.IncompleteCountItems e -> 409;
            case InventoryCountError.SamePersonViolation e -> 409;
            case InventoryCountError.StockNotFoundForArticle e -> 409;
            case InventoryCountError.CountDateInFuture e -> 400;
            case InventoryCountError.InvalidStorageLocationId e -> 400;
            case InventoryCountError.InvalidCountDate e -> 400;
            case InventoryCountError.InvalidInitiatedBy e -> 400;
            case InventoryCountError.InvalidArticleId e -> 400;
            case InventoryCountError.InvalidQuantity e -> 400;
            case InventoryCountError.InvalidInventoryCountId e -> 400;
            case InventoryCountError.CancellationReasonRequired e -> 400;
            case InventoryCountError.InvalidStatus e -> 400;
            case InventoryCountError.Unauthorized e -> 403;
            case InventoryCountError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(StockMovementError error) {
        return switch (error) {
            case StockMovementError.StockMovementNotFound e -> 404;
            case StockMovementError.InvalidStockId e -> 400;
            case StockMovementError.InvalidArticleId e -> 400;
            case StockMovementError.InvalidStockBatchId e -> 400;
            case StockMovementError.InvalidBatchReference e -> 400;
            case StockMovementError.InvalidMovementType e -> 400;
            case StockMovementError.InvalidDirection e -> 400;
            case StockMovementError.InvalidQuantity e -> 400;
            case StockMovementError.ReasonRequired e -> 400;
            case StockMovementError.ReferenceDocumentRequired e -> 400;
            case StockMovementError.InvalidPerformedBy e -> 400;
            case StockMovementError.InvalidDateRange e -> 400;
            case StockMovementError.Unauthorized e -> 403;
            case StockMovementError.RepositoryFailure e -> 500;
        };
    }
}
