using System;
using System.ComponentModel;

namespace OpenCVStudio_v0
{
    public sealed class MixChannelsBlockProperties
    {
        private readonly ProjectManager projectManager;
        private readonly ProjectBlock block;
        private int channel0;
        private int channel1;
        private int channel2;

        public MixChannelsBlockProperties(ProjectManager projectManager, ProjectBlock block)
        {
            this.projectManager = projectManager ?? throw new ArgumentNullException(nameof(projectManager));
            this.block = block ?? throw new ArgumentNullException(nameof(block));
            channel0 = projectManager.GetBlockParameter(block.Id, "Channel0", 2);
            channel1 = projectManager.GetBlockParameter(block.Id, "Channel1", 1);
            channel2 = projectManager.GetBlockParameter(block.Id, "Channel2", 0);
        }

        [Category("Каналы")]
        [DisplayName("Выходной канал 0")]
        [Description("Какой входной канал копировать первым.")]
        public int Channel0
        {
            get => channel0;
            set
            {
                channel0 = Math.Clamp(value, 0, 2);
                projectManager.SetBlockParameter(block.Id, "Channel0", channel0);
            }
        }

        [Category("Каналы")]
        [DisplayName("Выходной канал 1")]
        public int Channel1
        {
            get => channel1;
            set
            {
                channel1 = Math.Clamp(value, 0, 2);
                projectManager.SetBlockParameter(block.Id, "Channel1", channel1);
            }
        }

        [Category("Каналы")]
        [DisplayName("Выходной канал 2")]
        public int Channel2
        {
            get => channel2;
            set
            {
                channel2 = Math.Clamp(value, 0, 2);
                projectManager.SetBlockParameter(block.Id, "Channel2", channel2);
            }
        }

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