using System;
using Valg.EVA.Skanning.Resources.Language;

namespace Valg.Eva.Skanning.Scan.Presentation.ErrorHandling
{
    [Serializable]
    public class ReadSoftException : Exception
    {
        public ReadSoftException(ReadSoftErrorCode readSoftErrorCode) :
            base(string.Format("Readsoft reported the following ReadSoftError error code: {0} which means: {1}", (int)readSoftErrorCode, TranslateErrorCode(readSoftErrorCode)))
        {}

        public ReadSoftException(NotifyUserErrorType userErrorType, string additionalErrorInfo)
            : base(string.Format("Readsoft reported the following NotifyUserErrorType error code: {0} which means: {1}. Additional error info: {2}", (int) userErrorType, userErrorType, additionalErrorInfo))
        {}
        
        public ReadSoftException(Exception innerException) 
            : base(string.Format("Readsoft or Readsoft API reported an unknown error"), innerException)
        {}
        
        private static string TranslateErrorCode(ReadSoftErrorCode errorCode)
        {
            string title = ScanLanguageString.ReadSoftErrorCode_NotHandled;
            
            if (errorCode == ReadSoftErrorCode.NoContactWithScanner)
            {
                title = ScanLanguageString.ReadSoftErrorCode_NoContactWithScanner;
            }

            return title;
        }
    }
}

