using System;
using System.Text.Json.Serialization;
namespace eSuite.Core.Miscellaneous;
///
/// General interface that can be used to identify an item.
/// To use this, will be expected to supply the Id or Guid.
/// If both at supplied, the Id is use primarily, and the Guid can then be used as a confirmation.
///
public class GeneralIdRef : IGeneralIdRef, IEquatable
{
[JsonPropertyName("id")]
public long? Id { get; set; }
[JsonPropertyName("Guid")]
public Guid? Guid { get; set; }
public bool Equals(GeneralIdRef? other)
{
if (Id == null || other?.Id == null)
{
return Nullable.Equals(Guid, other?.Guid);
}
if (Guid == null || other?.Guid == null)
{
return Nullable.Equals(Id, other?.Id);
}
return Nullable.Equals(Id, other?.Id) && Nullable.Equals(Guid, other?.Guid);
}
public override bool Equals(object? obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == this.GetType() && Equals(obj as GeneralIdRef);
}
public override int GetHashCode()
{
return HashCode.Combine(Id, Guid);
}
}