using System;
using System.Collections.Generic;
using System.Text;

using System;
using System.ComponentModel;
namespace OpenCVStudio_v0
{
    public sealed class GammaCorrectionBlockProperties
    {
        private readonly ProjectManager projectManager; private readonly ProjectBlock projectBlock;
        private double gamma;
        public GammaCorrectionBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            gamma = projectManager.GetBlockParameter(projectBlock.Id, "Gamma", 1.0);
        }
        [Category("Коррекция")]
        [DisplayName("Гамма")]
        [Description("Коэффициент гамма-коррекции. 1,0 — без изменений; больше 1 — осветление; меньше 1 — затемнение.")]
        public double Gamma
        {
            get => gamma;
            set
            {
                ValidateGamma(value);
                if (Math.Abs(gamma - value) < double.Epsilon) return;
                gamma = value;
                projectManager.SetBlockParameter(projectBlock.Id, "Gamma", value);
            }
        }
        [Category("Блок")]
        [DisplayName("Название")]
        [ReadOnly(true)]
        public string BlockName => projectBlock.Name;
        [Category("Блок")]
        [DisplayName("Тип")]
        [ReadOnly(true)]
        public string BlockType => projectBlock.BlockType;
        [Category("Блок")]
        [DisplayName("Позиция")]
        [ReadOnly(true)]
        public int Position => projectBlock.Order + 1;
        private static void ValidateGamma(double value)
        {
            if (double.IsNaN(value) || double.IsInfinity(value) || value < 0.01 || value > 10.0)
                throw new ArgumentOutOfRangeException(nameof(value), value, "Гамма должна находиться в диапазоне от 0,01 до 10,0.");
        }
    }
}