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

namespace Hawkeye.VisionBuilder.UI.Sources.Raspberry.Libcamera;

public class LibcameraCaptureSettings : ISettings
{
    public string CameraName { get; }

    public LibcameraCaptureSettings(string cameraName)
    {
        CameraName = cameraName;
    }

    public int Width { get; set; } = 2028;
    public int Height { get; set; } = 1520;
    public int ShutterSpeed { get; set; } = 10000;
    public int Framerate { get; set; } = 2;
    public double AwbGainRed { get; set; } = 3.86;
    public double AwbGainBlue { get; set; } = 1.46;

    public string BuildArguments()
    {
        return $"--codec mjpeg -t0 --width {Width} --height {Height} " +
               $"--shutter {ShutterSpeed} --framerate {Framerate} " +
               $"--awbgains {AwbGainRed:F2},{AwbGainBlue:F2} --nopreview -o -";
    }

    public void RegisterSettings(InspectronSettings settings)
    {
        settings.RegisterSimple(this, () => Width, CameraName + "/Sources/Libcamera", nameof(Width));
        settings.RegisterSimple(this, () => Height, CameraName + "/Sources/Libcamera", nameof(Height));
        settings.RegisterSimple(this, () => ShutterSpeed, CameraName + "/Sources/Libcamera", nameof(ShutterSpeed));
        settings.RegisterSimple(this, () => Framerate, CameraName + "/Sources/Libcamera", nameof(Framerate));
        settings.RegisterSimple(this, () => AwbGainRed, CameraName + "/Sources/Libcamera", nameof(AwbGainRed));
        settings.RegisterSimple(this, () => AwbGainBlue, CameraName + "/Sources/Libcamera", nameof(AwbGainBlue));
    }
}
