namespace RpgRoller.Services;

public sealed record ServiceError(string Code, string Message);

public sealed class ServiceResult<T>
{
    private ServiceResult(T value)
    {
        Value = value;
    }

    private ServiceResult(ServiceError error)
    {
        Error = error;
    }

    public static ServiceResult<T> Success(T value)
    {
        return new(value);
    }

    public static ServiceResult<T> Failure(string code, string message)
    {
        return new(new ServiceError(code, message));
    }

    public T? Value { get; }
    public ServiceError? Error { get; }
    public bool Succeeded => Error is null;
}