// Copyright (C) 2015-2026 The Neo Project.
//
// Nep17TransferKey.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Neo.IO;

namespace Neo.Plugins.Trackers.NEP_17;

public class Nep17TransferKey : TokenTransferKey, IComparable<Nep17TransferKey>, IEquatable<Nep17TransferKey>, ISerializable
{
    public Nep17TransferKey() : base(UInt160.Zero, 0, UInt160.Zero, 0) { }

    public Nep17TransferKey(UInt160 userScriptHash, ulong timestamp, UInt160 assetScriptHash, uint xferIndex)
    : base(userScriptHash, timestamp, assetScriptHash, xferIndex) { }

    public int CompareTo(Nep17TransferKey? other)
    {
        if (other is null) return 1;
        if (ReferenceEquals(this, other)) return 0;
        int result = UserScriptHash.CompareTo(other.UserScriptHash);
        if (result != 0) return result;
        int result2 = TimestampMS.CompareTo(other.TimestampMS);
        if (result2 != 0) return result2;
        int result3 = AssetScriptHash.CompareTo(other.AssetScriptHash);
        if (result3 != 0) return result3;
        return BlockXferNotificationIndex.CompareTo(other.BlockXferNotificationIndex);
    }

    public bool Equals(Nep17TransferKey? other)
    {
        if (other is null) return false;
        if (ReferenceEquals(this, other)) return true;
        return UserScriptHash.Equals(other.UserScriptHash)
               && TimestampMS.Equals(other.TimestampMS) && AssetScriptHash.Equals(other.AssetScriptHash)
               && BlockXferNotificationIndex.Equals(other.BlockXferNotificationIndex);
    }

    public override bool Equals(object? other)
    {
        return other is Nep17TransferKey otherKey && Equals(otherKey);
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(UserScriptHash.GetHashCode(), TimestampMS.GetHashCode(),
            AssetScriptHash.GetHashCode(), BlockXferNotificationIndex.GetHashCode());
    }
}
