using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    /// <summary>
    /// Параметры блока преобразования цвета,
    /// отображаемые в PropertyGrid.
    /// </summary>
    public sealed class CvtColorBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private ColorConversionMode conversionMode;

        public CvtColorBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            conversionMode = projectManager.GetBlockParameter(projectBlock.Id, "ConversionMode", ColorConversionMode.BgrToGray);
        }

        [Category("Параметры")]
        [DisplayName("Преобразование")]
        [Description("Направление преобразования цветового пространства.")]
        public ColorConversionMode ConversionMode
        {
            get => conversionMode;
            set
            {
                if (conversionMode == value)
                {
                    return;
                }
                conversionMode = value;
                projectManager.SetBlockParameter(projectBlock.Id, "ConversionMode", 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;
    }
}