using System;
using System.Collections.Generic;
using System.Text;

namespace Edge.Core.Configuration
{
    public class DeviceProcessorConfiguration
    {
        public List<Processor> Processor { get; set; }
        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (!(obj is DeviceProcessorConfiguration target)) return false;
            else
            {
                if (this.Processor.Count != target.Processor.Count) return false;
                for (int i = 0; i < this.Processor.Count; i++)
                    if (!this.Processor[i].Equals(target.Processor[i])) return false;
                return true;
            }
        }
    }

    public class Processor
    {
        /// <summary>
        /// Unique for each processor configuration in settings.xml
        /// </summary>
        public string Name { get; set; }

        
        public string DeviceProcessorType
        {
            get; set;
        }

        public bool Complex
        {
            get; set;
        }

        public string ConstructorArg
        {
            get; set;
        }

        //public bool IsComplex
        //{
        //    get; set;
        //}

        public string Description
        {
            get; set;
        }

        /// <summary>
        /// the high numbers have the earlier initial time.
        /// </summary>
        //public int InitPriority { get; set; }

        public List<ProcessorParameter> Parameter { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (!(obj is Processor target)) return false;
            else
            {
                if (this.Name != target.Name || this.DeviceProcessorType != target.DeviceProcessorType
                    //|| this.SerialNumber != target.SerialNumber
                    )
                    return false;
                if (this.Parameter == null && target.Parameter == null) return true;
                if (this.Parameter.Count != target.Parameter.Count) return false;
                for (int i = 0; i < this.Parameter.Count; i++)
                    if (!this.Parameter[i].Equals(target.Parameter[i])) return false;
                return true;
            }
        }
    }

    public class ProcessorParameter
    {
        public string Name
        {
            get; set;
        }
        public string Value
        {
            get; set;
        }

        public bool Complex
        {
            get; set;
        }

        public string ConstructorArg
        {
            get; set;
        }

        public string Description
        {
            get; set;
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (!(obj is ProcessorParameter target)) return false;
            else
            {
                if (this.Name != target.Name || this.Value != target.Value
                    || this.ConstructorArg != target.ConstructorArg)
                    return false;
                return true;
            }
        }
    }
}
