using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    /// <summary>
    /// Параметры блока скелетизации.
    /// </summary>
    public sealed class ThinningBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private ThinningAlgorithmMode algorithm;

        public ThinningBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            algorithm = projectManager.GetBlockParameter(projectBlock.Id, "Algorithm", ThinningAlgorithmMode.ZhangSuen);
        }

        [Category("Скелетизация")]
        [DisplayName("Алгоритм")]
        [Description("Алгоритм построения однопиксельного скелета бинарных объектов.")]
        public ThinningAlgorithmMode Algorithm
        {
            get => algorithm;
            set
            {
                if (algorithm == value)
                {
                    return;
                }
                algorithm = value;
                projectManager.SetBlockParameter(projectBlock.Id, "Algorithm", value);
            }
        }

        [Category("Информация")]
        [DisplayName("Описание алгоритма")]
        [ReadOnly(true)]
        public string AlgorithmDescription =>
            algorithm switch
            {
                ThinningAlgorithmMode.ZhangSuen => "Zhang-Suen — быстрый стандартный алгоритм скелетизации.",
                ThinningAlgorithmMode.GuoHall => "Guo-Hall — альтернативный алгоритм с хорошим сохранением связности.",
                _ => string.Empty
            };

        [Category("Блок")]
        [DisplayName("Название")]
        [ReadOnly(true)]
        public string BlockName => projectBlock.Name ?? string.Empty;

        [Category("Блок")]
        [DisplayName("Тип")]
        [ReadOnly(true)]
        public string BlockType => projectBlock.BlockType ?? string.Empty;

        [Category("Блок")]
        [DisplayName("Позиция")]
        [ReadOnly(true)]
        public int Position => projectBlock.Order + 1;
    }
}