package controller;

import image.BufferedImageDecorator;
import image.BufferedImageDecoratorException;
import image.ImageFactory;
import image.ImageFactoryException;
import image.filterStrategy.StatisticalFilterInterface;
import image.filterStrategy.WeightedBlendingFilter;
import java.awt.image.BufferedImage;

public class ImageController {

    public BufferedImage statisticalFilterAction(BufferedImage originalImage, StatisticalFilterInterface filter, int matrixSize) throws ImageFactoryException, BufferedImageDecoratorException, Exception {
        if (originalImage == null) {
            throw new Exception("Original image must be loaded prior to transformation");
        }
        if (filter == null) {
            throw new Exception("Statistical filter must be passed in order to create transformated image");
        }

        ImageFactory imageFactory = new ImageFactory();
        imageFactory.setStatisticalFilter(filter);

        BufferedImageDecorator image = new BufferedImageDecorator(originalImage);
        BufferedImage transformedImage = imageFactory.createStatistical(image, matrixSize);

        return transformedImage;
    }

    public BufferedImage blendAction(BufferedImage originalImage, BufferedImage transformedImage, int weight) throws ImageFactoryException, BufferedImageDecoratorException, Exception {
        if (originalImage == null) {
            throw new Exception("Original image must be loaded prior to blending");
        }
        if (transformedImage == null) {
            throw new Exception("Transformed image must be created prior to blending");
        }

        ImageFactory imageFactory = new ImageFactory();
        imageFactory.setBlendingFilter(new WeightedBlendingFilter());

        BufferedImage blendedImage = imageFactory.createBlend(originalImage, transformedImage, weight);

        return blendedImage;
    }

}
