using MultiversalDiplomacy.Orders;
namespace MultiversalDiplomacy.Adjudicate;
///
/// Represents the result of validating an order.
///
public class OrderValidation
{
///
/// The order that was validated.
///
public Order Order { get; }
///
/// Whether the order is valid.
///
public bool Valid { get; }
///
/// The reason for the order validation result.
///
public ValidationReason Reason { get; }
internal OrderValidation(Order order, bool valid, ValidationReason reason)
{
this.Order = order;
this.Valid = valid;
this.Reason = reason;
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})";
}
}
public static class OrderValidationExtensions
{
///
/// Create an accepting this order.
///
public static OrderValidation Validate(this Order order, ValidationReason reason)
=> new OrderValidation(order, true, reason);
///
/// Create an rejecting this order.
///
public static OrderValidation Invalidate(this Order order, ValidationReason reason)
=> new OrderValidation(order, false, reason);
}