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

import de.effigenix.domain.production.BatchError;
import de.effigenix.domain.production.ProductionOrderError;
import de.effigenix.domain.production.RecipeError;

public final class ProductionErrorHttpStatusMapper {

    private ProductionErrorHttpStatusMapper() {}

    public static int toHttpStatus(RecipeError error) {
        return switch (error) {
            case RecipeError.RecipeNotFound e -> 404;
            case RecipeError.IngredientNotFound e -> 404;
            case RecipeError.StepNotFound e -> 404;
            case RecipeError.NameAndVersionAlreadyExists e -> 409;
            case RecipeError.DuplicatePosition e -> 409;
            case RecipeError.DuplicateStepNumber e -> 409;
            case RecipeError.InvalidShelfLife e -> 400;
            case RecipeError.ValidationFailure e -> 400;
            case RecipeError.NotInDraftStatus e -> 409;
            case RecipeError.InvalidStatusTransition e -> 409;
            case RecipeError.NoIngredients e -> 400;
            case RecipeError.CyclicDependencyDetected e -> 400;
            case RecipeError.Unauthorized e -> 403;
            case RecipeError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(BatchError error) {
        return switch (error) {
            case BatchError.BatchNotFound e -> 404;
            case BatchError.BatchNotFoundByNumber e -> 404;
            case BatchError.InvalidPlannedQuantity e -> 400;
            case BatchError.InvalidDates e -> 400;
            case BatchError.RecipeNotActive e -> 409;
            case BatchError.InvalidStatusTransition e -> 409;
            case BatchError.NotInProduction e -> 409;
            case BatchError.DuplicateInputBatch e -> 409;
            case BatchError.InvalidConsumptionQuantity e -> 400;
            case BatchError.MissingConsumptions e -> 409;
            case BatchError.InvalidActualQuantity e -> 400;
            case BatchError.InvalidWaste e -> 400;
            case BatchError.CancellationReasonRequired e -> 400;
            case BatchError.CancellationReasonTooLong e -> 400;
            case BatchError.ValidationFailure e -> 400;
            case BatchError.Unauthorized e -> 403;
            case BatchError.RepositoryFailure e -> 500;
        };
    }

    public static int toHttpStatus(ProductionOrderError error) {
        return switch (error) {
            case ProductionOrderError.ProductionOrderNotFound e -> 404;
            case ProductionOrderError.InvalidPlannedQuantity e -> 400;
            case ProductionOrderError.PlannedDateInPast e -> 400;
            case ProductionOrderError.InvalidPriority e -> 400;
            case ProductionOrderError.RecipeNotFound e -> 404;
            case ProductionOrderError.RecipeNotActive e -> 409;
            case ProductionOrderError.InvalidStatusTransition e -> 409;
            case ProductionOrderError.RescheduleNotAllowed e -> 409;
            case ProductionOrderError.BatchAlreadyAssigned e -> 409;
            case ProductionOrderError.BatchNotCompleted e -> 409;
            case ProductionOrderError.BatchCreationFailed e -> 400;
            case ProductionOrderError.ValidationFailure e -> 400;
            case ProductionOrderError.Unauthorized e -> 403;
            case ProductionOrderError.RepositoryFailure e -> 500;
        };
    }
}
