using System;
using System.ComponentModel;
using System.Drawing.Design;

namespace OpenCVStudio_v0
{
    public sealed class ImageSaveBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock projectBlock;
        private string filePath;

        public ImageSaveBlockProperties(ProjectManager projectManager, ProjectBlock projectBlock)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.projectBlock = projectBlock ?? throw new ArgumentNullException(nameof(projectBlock));
            filePath = projectManager.GetBlockParameter(projectBlock.Id, "FilePath", "result.png");
        }

        [Category("Сохранение")]
        [DisplayName("Файл")]
        [Description("Путь и имя файла для сохранения изображения.")]
        [Editor(typeof(FilePathEditor), typeof(UITypeEditor))]
        public string FilePath
        {
            get => filePath;
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    return;
                filePath = value;
                projectManager.SetBlockParameter(projectBlock.Id, "FilePath", 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;
    }
}