# -*- coding: utf-8 -*-

# Copyright(C) 2014 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.

from weboob.exceptions import BrowserIncorrectPassword as _BrowserIncorrectPassword
class BrowserIncorrectPassword(_BrowserIncorrectPassword):
    pass


from weboob.exceptions import BrowserForbidden as _BrowserForbidden
class BrowserForbidden(_BrowserForbidden):
    pass


from weboob.exceptions import BrowserBanned as _BrowserBanned
class BrowserBanned(_BrowserBanned):
    pass


from weboob.exceptions import BrowserUnavailable as _BrowserUnavailable
class BrowserUnavailable(_BrowserUnavailable):
    pass


from weboob.exceptions import BrowserInteraction as _BrowserInteraction
class BrowserInteraction(_BrowserInteraction):
    pass


from weboob.exceptions import BrowserQuestion as _BrowserQuestion
class BrowserQuestion(_BrowserQuestion):
    """
    When raised by a browser,
    """
    def __init__(self, *fields):
        self.fields = fields


class DecoupledValidation(BrowserInteraction):
    def __init__(self, message='', resource=None, *values):
        super(DecoupledValidation, self).__init__(*values)
        self.message = message
        self.resource = resource

    def __str__(self):
        return self.message


class AppValidation(DecoupledValidation):
    pass


from weboob.exceptions import BrowserRedirect as _BrowserRedirect
class BrowserRedirect(_BrowserRedirect):
    def __init__(self, url, resource=None):
        self.url = url

        # Needed for transfer redirection
        self.resource = resource

    def __str__(self):
        return 'Redirecting to %s' % self.url


from weboob.exceptions import CaptchaQuestion as _CaptchaQuestion
class CaptchaQuestion(_CaptchaQuestion):
    """Site requires solving a CAPTCHA (base class)"""
    # could be improved to pass the name of the backendconfig key

    def __init__(self, type=None, **kwargs):
        super(CaptchaQuestion, self).__init__("The site requires solving a captcha")
        self.type = type
        for key, value in kwargs.items():
            setattr(self, key, value)


class WrongCaptchaResponse(Exception):
    """when website tell us captcha response is not good"""
    def __init__(self, message=None):
        super(WrongCaptchaResponse, self).__init__(message or "Captcha response is wrong")


from weboob.exceptions import ImageCaptchaQuestion as _ImageCaptchaQuestion
class ImageCaptchaQuestion(_ImageCaptchaQuestion):
    type = 'image_captcha'

    image_data = None

    def __init__(self, image_data):
        super(ImageCaptchaQuestion, self).__init__(self.type, image_data=image_data)


from weboob.exceptions import NocaptchaQuestion as _NocaptchaQuestion
class NocaptchaQuestion(_NocaptchaQuestion):
    type = 'g_recaptcha'

    website_key = None
    website_url = None

    def __init__(self, website_key, website_url):
        super(NocaptchaQuestion, self).__init__(self.type, website_key=website_key, website_url=website_url)


from weboob.exceptions import RecaptchaQuestion as _RecaptchaQuestion
class RecaptchaQuestion(_RecaptchaQuestion):
    type = 'g_recaptcha'

    website_key = None
    website_url = None

    def __init__(self, website_key, website_url):
        super(RecaptchaQuestion, self).__init__(self.type, website_key=website_key, website_url=website_url)


class RecaptchaV3Question(CaptchaQuestion):
    type = 'g_recaptcha'

    website_key = None
    website_url = None
    action = None

    def __init__(self, website_key, website_url, action=None):
        super(RecaptchaV3Question, self).__init__(self.type, website_key=website_key, website_url=website_url)
        self.action = action


from weboob.exceptions import FuncaptchaQuestion as _FuncaptchaQuestion
class FuncaptchaQuestion(_FuncaptchaQuestion):
    type = 'funcaptcha'

    website_key = None
    website_url = None
    sub_domain = None

    def __init__(self, website_key, website_url, sub_domain=None):
        super(FuncaptchaQuestion, self).__init__(
            self.type, website_key=website_key, website_url=website_url, sub_domain=sub_domain)


from weboob.exceptions import BrowserHTTPNotFound as _BrowserHTTPNotFound
class BrowserHTTPNotFound(_BrowserHTTPNotFound):
    pass


from weboob.exceptions import BrowserHTTPError as _BrowserHTTPError
class BrowserHTTPError(_BrowserHTTPError):
    pass


from weboob.exceptions import BrowserHTTPSDowngrade as _BrowserHTTPSDowngrade
class BrowserHTTPSDowngrade(_BrowserHTTPSDowngrade):
    pass


from weboob.exceptions import BrowserSSLError as _BrowserSSLError
class BrowserSSLError(_BrowserSSLError):
    pass


from weboob.exceptions import ParseError as _ParseError
class ParseError(_ParseError):
    pass


from weboob.exceptions import FormFieldConversionWarning as _FormFieldConversionWarning
class FormFieldConversionWarning(_FormFieldConversionWarning):
    """
    A value has been set to a form's field and has been implicitly converted.
    """


from weboob.exceptions import NoAccountsException as _NoAccountsException
class NoAccountsException(_NoAccountsException):
    pass


from weboob.exceptions import ModuleInstallError as _ModuleInstallError
class ModuleInstallError(_ModuleInstallError):
    pass


from weboob.exceptions import ModuleLoadError as _ModuleLoadError
class ModuleLoadError(_ModuleLoadError):
    def __init__(self, module_name, msg):
        super(ModuleLoadError, self).__init__(msg)
        self.module = module_name


from weboob.exceptions import ActionNeeded as _ActionNeeded
class ActionNeeded(_ActionNeeded):
    pass


from weboob.exceptions import AuthMethodNotImplemented as _AuthMethodNotImplemented
class AuthMethodNotImplemented(_AuthMethodNotImplemented):
    pass


from weboob.exceptions import BrowserPasswordExpired as _BrowserPasswordExpired
class BrowserPasswordExpired(_BrowserPasswordExpired):
    pass

