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

namespace Inspectron.Camera.UEye;

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

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

    [SettingPreview(typeof(IDSImageSourceSettings), nameof(CameraIdsPreview))]
    public int CameraId { get; set; } = 0;

    [File("*.ini")] public string CameraFile { get; set; } = "";

    public void RegisterSettings(InspectronSettings settings)
    {
        settings.RegisterSimple(this, () => CameraId, $"{CameraName}/Sources/IDS", nameof(CameraId));
        settings.RegisterSimple(this, () => CameraFile, $"{CameraName}/Sources/IDS", nameof(CameraFile));
        
    }

    public static string CameraIdsPreview(int _)
    {
        uEye.Info.Camera.GetCameraList(out var cameraList);
        StringBuilder sb = new StringBuilder();
        foreach (var camera in cameraList)
        {
            sb.Append($"{camera.CameraID}[{camera.SerialNumber}]");
        }

        return sb.ToString();
    }
}