using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    /// <summary>
    /// Параметры блока цветовой карты.
    /// </summary>
    public sealed class ApplyColorMapBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private ColorMapMode colorMap;

        public ApplyColorMapBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            colorMap = projectManager.GetBlockParameter(projectBlock.Id, "ColorMap", ColorMapMode.Jet);
        }

        [Category("Параметры")]
        [DisplayName("Цветовая карта")]
        [Description("Палитра, используемая для преобразования значений яркости 0–255 в цвета.")]
        [DefaultValue(ColorMapMode.Jet)]
        public ColorMapMode ColorMap
        {
            get => colorMap;
            set
            {
                if (colorMap == value)
                {
                    return;
                }
                colorMap = value;
                projectManager.SetBlockParameter(projectBlock.Id, "ColorMap", value);
            }
        }

        [Category("Подсказка")]
        [DisplayName("Назначение")]
        [ReadOnly(true)]
        public string Purpose => "Преобразует CV_8UC1 в цветное CV_8UC3";

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