using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;

namespace MECF.Framework.UI.Client.RecipeEditorLib.DGExtension.CustomColumn
{
    public class ComboxColumn : EditorDataGridTemplateColumnBase
    {
        public ComboxColumn() : base()
        {
            Options = new List<Option>();
        }

        public List<Option> Options { get; }

        
        public class Option : IEquatable<Option>, IEquatable<Enum> , IEquatable<string>, IComparable<Option>
        {
            public Option(string displayName, string controlName, string relatedParameters)
            {
                DisplayName = displayName;
                ControlName = controlName;
                RelatedParameters = relatedParameters;
            }

            public Option(string displayName, string controlName) : 
                this(displayName, controlName, string.Empty)
            {
                
            }

            public string ControlName { get; }

            public string DisplayName { get; }

            public string RelatedParameters { get; }

            public override bool Equals(object other)
            {
                return other switch
                {
                    null => false,
                    Option destOption => DisplayName == destOption.DisplayName,
                    _ => DisplayName == other.ToString()
                };
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    var hashCode = (ControlName != null ? ControlName.GetHashCode() : 0);
                    hashCode = (hashCode * 397) ^ (DisplayName != null ? DisplayName.GetHashCode() : 0);
                    hashCode = (hashCode * 397) ^ (RelatedParameters != null ? RelatedParameters.GetHashCode() : 0);
                    return hashCode;
                }
            }

            public int CompareTo(Option other)
            {
                if (DisplayName == other.DisplayName)
                    return 0;

                return -1;
            }

            public bool Equals(Option other)
            {
                if (other == null)
                    return false;

                return DisplayName == other.DisplayName;
            }

            public bool Equals(Enum other)
            {
                if (other == null)
                    return false;
                    
                return DisplayName == other.ToString();
            }

            public bool Equals(string other)
            {
                if (string.IsNullOrEmpty(other))
                    return false;

                return DisplayName == other;
            }

            public override string ToString()
            {
                return DisplayName;
            }
        }
    }
}
