using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp;

namespace Hawkeye.VisionBuilder.Workflow.Operations.Image;

[Category("Image")]
public class ConvertOperation: BaseOperation
{
    public enum EConversionType
    {
        RGBToHSV,
        HSVToRGB,
    }
    public ConvertOperation()
    {
        CanHaveProcessingError = false;
    }

    public EConversionType ConversionType { get; set; }
    protected override void InterpretInternal(Context context)
    {
        if (!CheckImageExists(context)) return;
        var mat = context.ActiveImage.ImageData;
        Mat res;
        switch (ConversionType)
        {
            case EConversionType.RGBToHSV:
                res = mat.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2HSV);
                break;
            case EConversionType.HSVToRGB:
                res = mat.CvtColor(OpenCvSharp.ColorConversionCodes.HSV2BGR);
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
        
        context.ActiveImage = new HawkeyeImage() { ImageData = res};
        Status = "";
        Result = true;
    }


}