using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseDomain.Results
{
    public class Result<TValue> : Result
    {
        private readonly TValue _value;

        protected Result(TValue value, bool isSuccess, Error error) : base(isSuccess, error)
        {
            _value = value;
        }

        protected Result(TValue value) : base(true, Error.None)
        {
            _value = value;
        }

        public TValue Value => IsSuccess ? _value : throw new InvalidOperationException("O valor náo pode ser processado!");

        public static implicit operator Result<TValue>(TValue? value) => Create(value);
        public static Result<TValue> Success<TValue>(TValue value) => new(value);

        public static Result<TValue> Create(TValue value)
        {
            return new Result<TValue>(value, true, Error.None); 
        }

    }
}
