using Inspectron.Settings;
using Inspectron.Settings.Attributes;
using VisionBuilder.UI.Common;

namespace VisionBuilder.UI.IOCommander.Settings;

public class IOCommanderSettings : ISettings
{
    public IOCommanderCameraSettings[] Cameras { get; }
    public int PulseLength { get; set; } = 100;
    public bool ShowDebugView { get; set; } = false;
    public string Port { get; set; } = "COM3";
    public bool Enabled { get; set; }

    public List<IOCommanderProcessingEvent> GlobalEvents { get; set; } =
    [
        new(EProcessingEvent.ProgramStarted),
        new(EProcessingEvent.ProgramEnded),
    ];

    public IOCommanderSettings(IOCommanderCameraSettings[] cameras)
    {
        Cameras = cameras;
    }

    public void RegisterSettings(InspectronSettings settings)
    {
        settings.RegisterSimple(this, () => Port, "IOCommander", nameof(Port));
        settings.RegisterSimple(this, () => PulseLength, "IOCommander", nameof(PulseLength));
        settings.RegisterSimple(this, () => ShowDebugView, "IOCommander", nameof(ShowDebugView));
        settings.RegisterSimple(this, () => Enabled, "IOCommander", nameof(Enabled));

        foreach (IOCommanderProcessingEvent @event in GlobalEvents)
        {
            settings.RegisterSimple(@event, () => @event.Actions,
                "IOCommander/Global outputs/" + @event.Event.ToString(), nameof(@event.Actions));
        }
    }
}