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

namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;

[Category("Morphology")]
public class SubtractOperation : BaseOperation
{
    public string SlotName { get; set; } = "Image";

    public SubtractOperation()
    {
        CanHaveProcessingError = false;
    }

    protected override void InterpretInternal(Context context)
    {
        if (!CheckImageExists(context)) return;
        if (!CheckGrayscale(context)) return;

        if (!context.Memory.ContainsKey(SlotName))
        {
            Status = "Slot not found";
            Result = false;
            return;
        }

        var first = context.ActiveImage;
        var second = context.Memory[SlotName];

        context.ActiveImage = new HawkeyeImage()
        {
            ImageData = first.ImageData - second.ImageData
        };

        Result = true;
    }

    public override void Save(BinaryWriter bw)
    {
        base.Save(bw);
    }

    public override void Load(BinaryReader br)
    {
        base.Load(br);
    }

    public override void Save(Dictionary<string, object> dict)
    {
        base.Save(dict);
    }

    public override void Load(Dictionary<string, object> dict)
    {
        base.Load(dict);
    }
}
