using System;

namespace KitsuneCafe.UI
{
    public readonly struct ElementId : IEquatable<ElementId>, IEquatable<Guid>
    {
        public readonly Guid Id;

        public ElementId(Guid id)
        {
            Id = id;
        }

        public static ElementId Create() => new(Guid.NewGuid());

        public bool Equals(Guid other)
        {
            return Id == other;
        }

        public bool Equals(ElementId other)
        {
            return Equals(other.Id);
        }

        public override bool Equals(object obj)
        {
            return (obj is ElementId eid && Equals(eid))
                || (obj is Guid guid && Equals(guid));
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(Id);
        }

        public override string ToString()
        {
            return Id.ToString();
        }

        public static bool operator !=(ElementId lhs, ElementId rhs) => !lhs.Equals(rhs);
        public static bool operator ==(ElementId lhs, ElementId rhs) => lhs.Equals(rhs);
    }
}