2022-02-18 22:52:15 +00:00
|
|
|
using MultiversalDiplomacy.Orders;
|
|
|
|
|
|
|
|
namespace MultiversalDiplomacy.Adjudicate;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents the result of validating an order.
|
|
|
|
/// </summary>
|
|
|
|
public class OrderValidation
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The order that was validated.
|
|
|
|
/// </summary>
|
|
|
|
public Order Order { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether the order is valid.
|
|
|
|
/// </summary>
|
|
|
|
public bool Valid { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The reason for the order validation result.
|
|
|
|
/// </summary>
|
|
|
|
public ValidationReason Reason { get; }
|
|
|
|
|
|
|
|
internal OrderValidation(Order order, bool valid, ValidationReason reason)
|
|
|
|
{
|
|
|
|
this.Order = order;
|
|
|
|
this.Valid = valid;
|
|
|
|
this.Reason = reason;
|
2022-03-23 05:11:14 +00:00
|
|
|
|
|
|
|
if (this.Valid != (this.Reason == ValidationReason.Valid))
|
|
|
|
{
|
|
|
|
throw new ArgumentException("Only valid orders should have the Valid reason");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return this.Valid ? "Valid" : $"Invalid ({this.Reason})";
|
2022-02-18 22:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class OrderValidationExtensions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Create an <see cref="OrderValidation"/> accepting this order.
|
|
|
|
/// </summary>
|
|
|
|
public static OrderValidation Validate(this Order order, ValidationReason reason)
|
|
|
|
=> new OrderValidation(order, true, reason);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create an <see cref="OrderValidation"/> rejecting this order.
|
|
|
|
/// </summary>
|
|
|
|
public static OrderValidation Invalidate(this Order order, ValidationReason reason)
|
|
|
|
=> new OrderValidation(order, false, reason);
|
|
|
|
}
|