using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    /// <summary>
    /// Параметры блока извлечения канала.
    /// </summary>
    public sealed class ExtractChannelBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private int channelIndex;

        public ExtractChannelBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            channelIndex = projectManager.GetBlockParameter(projectBlock.Id, "ChannelIndex", 0);
        }

        [Category("Параметры")]
        [DisplayName("Номер канала")]
        [Description("Индекс извлекаемого канала. Нумерация начинается с нуля.")]
        [DefaultValue(0)]
        public int ChannelIndex
        {
            get => channelIndex;
            set
            {
                /*
                 * Общий допустимый диапазон.
                 * Фактическое количество каналов
                 * проверит исполнитель.
                 */
                int correctedValue = Math.Clamp(value, 0, 3);
                if (channelIndex == correctedValue)
                {
                    return;
                }
                channelIndex = correctedValue;
                projectManager.SetBlockParameter(projectBlock.Id, "ChannelIndex", correctedValue);
            }
        }

        [Category("Подсказка")]
        [DisplayName("BGR")]
        [ReadOnly(true)]
        public string BgrChannels => "0 = синий, 1 = зелёный, 2 = красный";

        [Category("Подсказка")]
        [DisplayName("HSV")]
        [ReadOnly(true)]
        public string HsvChannels => "0 = тон, 1 = насыщенность, 2 = яркость";

        [Category("Подсказка")]
        [DisplayName("BGRA")]
        [ReadOnly(true)]
        public string BgraChannels => "0 = B, 1 = G, 2 = R, 3 = Alpha";

        [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;
    }
}