using System.Runtime.InteropServices;
namespace PKHeX.Core;
///
/// Result of a Legality Check
///
[System.Diagnostics.DebuggerDisplay($"{{{nameof(Identifier)}}}: {{{nameof(Result)}}}")]
[StructLayout(LayoutKind.Explicit, Size = 8)]
public readonly record struct CheckResult
{
/// Indicates whether the result is valid.
public bool Valid => Judgement != Severity.Invalid;
/// Indicates if the result isn't a generic "Valid" result, and might be worth displaying to the user.
public bool IsNotGeneric() => Result != LegalityCheckResultCode.Valid;
/// Indicates the severity of the result.
[field: FieldOffset(0)] public required Severity Judgement { get; init; }
/// Identifier for the check group that produced this result.
[field: FieldOffset(1)] public required CheckIdentifier Identifier { get; init; }
/// Result code for the check, indicating the analysis performed/flagged to arrive at the .
[field: FieldOffset(2)] public required LegalityCheckResultCode Result { get; init; }
#region Hint Parameters used for Human-readable messages
/// Raw value used for hints, or storing a 32-bit number hint.
[field: FieldOffset(4)] public uint Value { get; init; }
/// First argument used for hints, or storing a 16-bit number hint.
[field: FieldOffset(4)] public ushort Argument { get; init; }
/// Second argument used for hints, or storing a 16-bit number hint.
[field: FieldOffset(6)] public ushort Argument2 { get; init; }
#endregion
///
/// Simple method to create a valid result with the given identifier.
///
public static CheckResult GetValid(CheckIdentifier ident) => Get(Severity.Valid, ident, LegalityCheckResultCode.Valid);
///
/// Simple method to create a result with the given parameters.
///
public static CheckResult Get(Severity judge, CheckIdentifier ident, LegalityCheckResultCode code, uint value = 0) => new()
{
Judgement = judge,
Identifier = ident,
Result = code,
Value = value,
};
}