using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    public sealed class FastNlMeansDenoisingBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock block;
        private float h;
        private int templateWindowSize;
        private int searchWindowSize;

        public FastNlMeansDenoisingBlockProperties(ProjectManager projectManager, ProjectBlock block)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.block = block ?? throw new ArgumentNullException(nameof(block));
            h = projectManager.GetBlockParameter(block.Id, "H", 10f);
            templateWindowSize = projectManager.GetBlockParameter(block.Id, "TemplateWindowSize", 7);
            searchWindowSize = projectManager.GetBlockParameter(block.Id, "SearchWindowSize", 21);
        }

        [Category("Шум")]
        [DisplayName("Сила фильтра")]
        public float H
        {
            get => h;
            set
            {
                h = Math.Max(0, value);
                projectManager.SetBlockParameter(block.Id, "H", h);
            }
        }

        [Category("Окно")]
        [DisplayName("Размер шаблона")]
        public int TemplateWindowSize
        {
            get => templateWindowSize;
            set
            {
                templateWindowSize = Math.Max(3, value | 1);
                projectManager.SetBlockParameter(block.Id, "TemplateWindowSize", templateWindowSize);
            }
        }

        [Category("Окно")]
        [DisplayName("Размер поиска")]
        public int SearchWindowSize
        {
            get => searchWindowSize;
            set
            {
                searchWindowSize = Math.Max(3, value | 1);
                projectManager.SetBlockParameter(block.Id, "SearchWindowSize", searchWindowSize);
            }
        }

        [Category("Блок")]
        [ReadOnly(true)]
        public string Name => block.Name;
    }
}