using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;

namespace Hawkeye.VisionBuilder.Workflow.Operations.Memory;

[Category("Memory")]
public class ImageToMemoryOperation:BaseOperation
{
    public ImageToMemoryOperation()
    {
        CanHaveProcessingError = false;
    }

    public string SlotName { get; set; } = "Image";

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

        context.Memory[SlotName] = context.ActiveImage!;
        Status = "Image to slot "+SlotName;

        Result = true;
    }

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

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

    public override void Save(Dictionary<string, object> dict)
    {
        base.Save(dict);
        dict[nameof(SlotName)] = SlotName;
    }

    public override void Load(Dictionary<string, object> dict)
    {
        base.Load(dict);
        if (dict.ContainsKey(nameof(SlotName)))
            SlotName = dict[nameof(SlotName)].ToString();
    }
}