using System.Runtime.CompilerServices;

namespace Reloaded.Memory.Sigscan.Definitions.Structs;

/// <summary />
public struct PatternScanResult
{
    /// <summary>
    /// The offset of the pattern if found, else -1.
    /// </summary>
    public int Offset { get; internal set; }

    /// <summary>
    /// True if the pattern has been found, else false.
    /// </summary>
    public bool Found => Offset != -1;

    /// <summary>
    /// Creates a pattern scan result given the offset of the pattern.
    /// </summary>
    /// <param name="offset">The offset of the pattern if found. -1 if not found.</param>
    public PatternScanResult(int offset)
    {
        Offset = offset;
    }

    /// <summary>
    /// Appends to the existing offset if the offset is valid.
    /// </summary>
#if NETCOREAPP3_0_OR_GREATER
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
    public PatternScanResult AddOffset(int offset)
    {
        return Offset != -1 ? new PatternScanResult(Offset + offset) : this;
    }

    /* Autogenerated by R# */
    /// <summary/>
    public bool Equals(PatternScanResult other)
    {
        return Offset == other.Offset;
    }

    /// <inheritdoc />
    public override bool Equals(object obj)
    {
        return obj is PatternScanResult other && Equals(other);
    }

    /// <inheritdoc />
    public override int GetHashCode()
    {
        return Offset;
    }
}