| | 1 | | namespace NostrSure.Domain.Validation; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Represents the result of a validation operation with rich error information |
| | 5 | | /// </summary> |
| | 6 | | public readonly record struct ValidationResult |
| | 7 | | { |
| 1077 | 8 | | public bool IsValid { get; init; } |
| 54 | 9 | | public ValidationError? Error { get; init; } |
| 23 | 10 | | public ValidationSeverity Severity { get; init; } |
| | 11 | |
|
| 522 | 12 | | public static ValidationResult Success() => new() { IsValid = true }; |
| | 13 | |
|
| | 14 | | public static ValidationResult Failure(string message, ValidationSeverity severity = ValidationSeverity.Error) |
| 2 | 15 | | => new() { IsValid = false, Error = new ValidationError(message), Severity = severity }; |
| | 16 | |
|
| | 17 | | public static ValidationResult Failure(string message, string? code, ValidationSeverity severity = ValidationSeverit |
| 10 | 18 | | => new() { IsValid = false, Error = new ValidationError(message, code), Severity = severity }; |
| | 19 | |
|
| | 20 | | public static ValidationResult Failure(string message, Exception exception, ValidationSeverity severity = Validation |
| 3 | 21 | | => new() { IsValid = false, Error = new ValidationError(message, InnerException: exception), Severity = severity |
| | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Represents detailed information about a validation error |
| | 26 | | /// </summary> |
| | 27 | | public record ValidationError(string Message, string? Code = null, Exception? InnerException = null); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Indicates the severity level of a validation error |
| | 31 | | /// </summary> |
| | 32 | | public enum ValidationSeverity |
| | 33 | | { |
| | 34 | | Warning, |
| | 35 | | Error, |
| | 36 | | Critical |
| | 37 | | } |