using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    public sealed class MultiplyScalarBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private double scale;

        public MultiplyScalarBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            scale = projectManager.GetBlockParameter(projectBlock.Id, "Scale", 1.0);
        }

        [Category("Параметры")]
        [DisplayName("Коэффициент")]
        [Description("Множитель яркости изображения.")]
        public double Scale
        {
            get => scale;
            set
            {
                double newValue = Math.Clamp(value, 0.0, 10.0);
                if (Math.Abs(scale - newValue) < double.Epsilon)
                {
                    return;
                }
                scale = newValue;
                projectManager.SetBlockParameter(projectBlock.Id, "Scale", newValue);
            }
        }

        [Category("Информация")]
        [DisplayName("Описание")]
        [ReadOnly(true)]
        public string Description => "Умножает значения пикселей на коэффициент.";

        [Category("Блок")]
        [DisplayName("Название")]
        [ReadOnly(true)]
        public string BlockName => projectBlock.Name ?? string.Empty;

        [Category("Блок")]
        [DisplayName("Тип")]
        [ReadOnly(true)]
        public string BlockType => projectBlock.BlockType ?? string.Empty;

        [Category("Блок")]
        [DisplayName("Позиция")]
        [ReadOnly(true)]
        public int Position => projectBlock.Order + 1;
    }
}