using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    public sealed class DemosaicingBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private DemosaicingPattern pattern;
        private DemosaicingAlgorithm algorithm;

        public DemosaicingBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            pattern = projectManager.GetBlockParameter(projectBlock.Id, "Pattern", DemosaicingPattern.RGGB);
            algorithm = projectManager.GetBlockParameter(projectBlock.Id, "Algorithm", DemosaicingAlgorithm.EdgeAware);
        }

        [Category("Bayer")]
        [DisplayName("Шаблон")]
        [Description("Расположение цветных пикселей Bayer.")]
        public DemosaicingPattern Pattern
        {
            get => pattern;
            set
            {
                pattern = value;
                projectManager.SetBlockParameter(projectBlock.Id, "Pattern", value);
            }
        }

        [Category("Bayer")]
        [DisplayName("Алгоритм")]
        [Description("Метод восстановления отсутствующих цветовых компонентов.")]
        public DemosaicingAlgorithm Algorithm
        {
            get => algorithm;
            set
            {
                algorithm = value;
                projectManager.SetBlockParameter(projectBlock.Id, "Algorithm", 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;
    }
}