using System.Text;
using Quadarax.Foundation.Core.Exceptions;

namespace Quadarax.Foundation.Core.Data
{
    public class Error : IError
    {
        #region *** Properties ***
        public string Message { get; }
        public int Code { get; }
        public ErrorLevelEnum Level { get; }

        #endregion

        #region *** Constructors ***
        public Error(string message, int code, ErrorLevelEnum level)
        {
            Message = message;
            Code = code;
            Level = level;
        }
        public Error(Exception exception)
        {
            if (exception==null)
                throw new ArgumentNullException(nameof(exception));

            Message = exception.Message;
            Code = exception.GetCode();
        }
        #endregion

        #region *** Operations ***
        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Append("Error");
            if (Code != 0)
                sb.Append("[").Append(Code).Append("]");
            sb.Append(":").Append(Message);
            return sb.ToString();
        }

        #endregion
    }
}
