using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    /// <summary>
    /// Параметры блока вычисления длины контуров.
    /// </summary>
    public sealed class ArcLengthBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private bool closed;

        public ArcLengthBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            closed = projectManager.GetBlockParameter(projectBlock.Id, "Closed", true);
        }

        [Category("Расчёт")]
        [DisplayName("Замкнутый контур")]
        [Description("Если включено, OpenCV добавляет расстояние между последней и первой точкой контура. Для обычных контуров FindContours параметр рекомендуется оставлять включённым.")]
        public bool Closed
        {
            get => closed;
            set
            {
                if (closed == value) return;
                closed = value;
                projectManager.SetBlockParameter(projectBlock.Id, "Closed", 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;
    }
}