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

namespace Quadarax.Foundation.Core.Data.Interface.Entity.Dto
{
    public class ErrorMessageDto : IDto, IError
    {
        /// <summary>
        /// <inheritdoc cref="IError.Message"/>
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// <inheritdoc cref="IError.Code"/>
        /// </summary>
        public int Code { get; set; }

        public ErrorMessageDto(){}
        public ErrorMessageDto(Exception exception, int code)
        {
            if (exception==null)
                throw new ArgumentNullException(nameof(exception));

            Message = exception.Message;
            Code = code;
        }

        public ErrorMessageDto(CodeException exception)
        {
            if (exception==null)
                throw new ArgumentNullException(nameof(exception));

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