using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    /// <summary>
    /// Свойства блока возведения в степень.
    /// </summary>
    public sealed class PowBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private double power;

        public PowBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            power = projectManager.GetBlockParameter(projectBlock.Id, "Power", 1.0);
        }

        [Category("Параметры")]
        [DisplayName("Степень")]
        [Description("Степень возведения значения пикселя.")]
        public double Power
        {
            get => power;
            set
            {
                double newValue = Math.Clamp(value, 0.01, 5.0);
                if (Math.Abs(power - newValue) < double.Epsilon)
                {
                    return;
                }
                power = newValue;
                projectManager.SetBlockParameter(projectBlock.Id, "Power", 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;
    }
}