using System.Text.Json.Serialization; namespace DigitalData.Core.Abstraction.Application.DTO; /// /// Represents the result of an operation, containing information about its success or failure, /// messages for the client, and notices for logging. /// [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public class Result { /// /// Gets or sets a value indicating whether the operation was successful. /// [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public bool IsSuccess { get; set; } = false; /// /// Gets a value indicating whether the operation failed. /// [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public bool IsFailed => !IsSuccess; /// /// Gets a list of messages intended for the client. /// [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public List Messages { get; init; } = new(); /// /// Gets a list of notices intended for logging purposes. This property is ignored during JSON serialization. /// [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] [JsonIgnore] public List Notices = new(); /// /// Creates a with the specified data. /// /// The type of the data. /// The data to include in the result. /// A new instance. [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public DataResult Data(T data) => new() { IsSuccess = IsSuccess, Messages = Messages, Notices = Notices, Data = data }; /// /// Checks if any notice has the specified flag. /// /// The flag to check. /// True if any notice has the specified flag; otherwise, false. [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString()); /// /// Checks if any notice has any of the specified flags. /// /// The flags to check. /// True if any notice has any of the specified flags; otherwise, false. [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public bool HasAnyFlag(params Enum[] flags) => flags.Any(HasFlag); /// /// Creates a new successful . /// /// A new successful . [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public static Result Success() => new() { IsSuccess = true }; /// /// Creates a new failed . /// /// A new failed . [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public static Result Fail() => new() { IsSuccess = false }; /// /// Creates a new successful with the specified data. /// /// The type of the data. /// The data to include in the result. /// A new successful with the specified data. [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] public static DataResult Success(T data) => new() { IsSuccess = true, Data = data }; /// /// Creates a new failed with no data. /// /// The type of the data. /// A new failed with no data. [Obsolete("Use DigitalData.Core.Exceptions and .Middleware")] #pragma warning disable CS8601 // Possible null reference assignment. public static DataResult Fail() => new() { IsSuccess = false, Data = default }; #pragma warning restore CS8601 // Possible null reference assignment. }