using System;
using System.ComponentModel;
namespace OpenCVStudio_v0
{
    public sealed class LutBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock block;
        private LutMode mode;
        private double gamma;
        private int threshold;

        public LutBlockProperties(ProjectManager projectManager, ProjectBlock block)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.block = block ?? throw new ArgumentNullException(nameof(block));
            mode = projectManager.GetBlockParameter(block.Id, "Mode", LutMode.Identity);
            gamma = projectManager.GetBlockParameter(block.Id, "Gamma", 1.0);
            threshold = projectManager.GetBlockParameter(block.Id, "Threshold", 128);
        }

        [Category("LUT")]
        [DisplayName("Режим")]
        public LutMode Mode
        {
            get => mode;
            set
            {
                mode = value;
                projectManager.SetBlockParameter(block.Id, "Mode", value);
            }
        }

        [Category("LUT")]
        [DisplayName("Гамма")]
        [Description("Коэффициент гамма-коррекции.")]
        public double Gamma
        {
            get => gamma;
            set
            {
                gamma = Math.Max(0.01, value);
                projectManager.SetBlockParameter(block.Id, "Gamma", gamma);
            }
        }

        [Category("LUT")]
        [DisplayName("Порог")]
        public int Threshold
        {
            get => threshold;
            set
            {
                threshold = Math.Clamp(value, 0, 255);
                projectManager.SetBlockParameter(block.Id, "Threshold", threshold);
            }
        }

        [Category("Блок")]
        [ReadOnly(true)]
        public string Name => block.Name;
    }
}