namespace Eshop.Application.Common;

public class ServiceResult
{
    public bool Success { get; protected set; }
    public IReadOnlyList<string> Errors { get; protected set; } = [];

    public static ServiceResult Ok() => new() { Success = true };

    public static ServiceResult Failure(string message) =>
        new() { Success = false, Errors = [message] };

    public static ServiceResult Failure(IEnumerable<string> errors) =>
        new() { Success = false, Errors = errors.ToList() };
}

public class ServiceResult<T> : ServiceResult
{
    public T? Data { get; private set; }

    public static ServiceResult<T> Ok(T data) => new() { Success = true, Data = data };

    public new static ServiceResult<T> Failure(string message) =>
        new() { Success = false, Errors = [message] };

    public new static ServiceResult<T> Failure(IEnumerable<string> errors) =>
        new() { Success = false, Errors = errors.ToList() };
}
