using System;
using System.Runtime.Serialization;

namespace BeWo.Service.ServiceContracts
{
    public enum BeWoFaultType
    {
        Unknown, 
        Concurrency, 
        DeleteNotPossible, 
        LoginNameTaken,
        CustomWithoutDetails
    }

    [DataContract]
    public class BeWoFault
    {
        public BeWoFault(Exception ex)
        {
            this.Message = ex.Message;
            this.StackTrace = ex.StackTrace;

            if (ex.InnerException != null)
            {
                this.InnerExceptionMessage = ex.InnerException.Message;
                this.InnerExceptionStackTrace = ex.InnerException.StackTrace;
            }

            this.FaultType = BeWoFaultType.Unknown;
        }

        public BeWoFault(string pMessage)
            : this(pMessage, BeWoFaultType.Unknown)
        {
        }

        public BeWoFault(string pMessage, BeWoFaultType pFaultType)
        {
            this.Message = pMessage;
            this.FaultType = pFaultType;
        }

        [DataMember]
        public BeWoFaultType FaultType { get; set; }

        [DataMember]
        public string InnerExceptionMessage { get; set; }

        [DataMember]
        public string InnerExceptionStackTrace { get; set; }

        [DataMember]
        public string Message { get; set; }

        [DataMember]
        public string StackTrace { get; set; }
    }
}