using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    public sealed class CompareScalarBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock block;
        private CompareOperation operation;
        private double value;

        public CompareScalarBlockProperties(ProjectManager projectManager, ProjectBlock block)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.block = block ?? throw new ArgumentNullException(nameof(block));
            operation = projectManager.GetBlockParameter(block.Id, "Operation", CompareOperation.Greater);
            value = projectManager.GetBlockParameter(block.Id, "Value", 128.0);
        }

        [Category("Сравнение")]
        [DisplayName("Операция")]
        public CompareOperation Operation
        {
            get => operation;
            set
            {
                operation = value;
                projectManager.SetBlockParameter(block.Id, "Operation", value);
            }
        }

        [Category("Сравнение")]
        [DisplayName("Значение")]
        public double Value
        {
            get => value;
            set
            {
                this.value = value;
                projectManager.SetBlockParameter(block.Id, "Value", value);
            }
        }

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