using System;
using System.ServiceModel;

namespace Valg.EVA.Skanning.ServicesModel.ServiceContracts.TransferCounting.Write
{
    public class TransferCountingResult
    {
        private TransferCountingResult(bool success, TransferCountingFailureDetails failureDetails = null)
        {
            this.Success = success;
            this.FailureDetails = failureDetails;
        }
       
        public bool Success { get; }
        public TransferCountingFailureDetails FailureDetails { get; }

        public static TransferCountingResult SuccessResult()
        {
            return new TransferCountingResult(true);
        }

        public static TransferCountingResult FailureWithUnhandledExceptionResult(int transferId, Exception exception)
        {
            return new TransferCountingResult(false, new TransferCountingFailureDetails(transferId, exception, TransferCountingFailureDetails.generalError));
        }

        public static TransferCountingResult FailureWithErrorCodeResult(int transferId, string faultCode, string faultString)
        {
            return new TransferCountingResult(false, new TransferCountingFailureDetails(transferId, faultCode, faultString));
        }

        public static TransferCountingResult FailureWithTimeoutExceptionResult(int transferId, TimeoutException timeoutException)
        {
            return new TransferCountingResult(false, new TransferCountingFailureDetails(transferId, timeoutException, TransferCountingFailureDetails.timeoutError));
        }

        public static TransferCountingResult FailureWithTimeoutExceptionResult(int transferId, CommunicationException communicationException)
        {
            return new TransferCountingResult(false, new TransferCountingFailureDetails(transferId, communicationException, TransferCountingFailureDetails.timeoutError));
        }
    }
}
