# Copyright(C) 2012 Kevin Pouget
#
# This file is part of a woob module.
#
# This woob module 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.
#
# This woob module 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 this woob module. If not, see <http://www.gnu.org/licenses/>.

from woob.capabilities.bank import Account
from woob_modules.caissedepargne.browser import CaisseEpargne
from woob_modules.caissedepargne.cenet.browser import CenetBrowser as _CenetBrowser
from woob_modules.linebourse.browser import LinebourseAPIBrowser

__all__ = ['CenetBrowser']


class CenetBrowser(_CenetBrowser):
    BASEURL = CENET_URL = 'https://www.espaceclient.credit-cooperatif.coop/'
    enseigne = 'ccoop'

    login = CaisseEpargne.login.with_urls(
        r'https://www.credit-cooperatif.coop/se-connecter/sso'
    )

    home_page = CaisseEpargne.home_page.with_urls(
        r'https://www.credit-cooperatif.coop/espace-entreprise/web-b2b/callback'
    )

    js_file = CaisseEpargne.js_file.with_urls(
        r'https://www.credit-cooperatif.coop/espace-entreprise/web-b2b/(?P<js_file_name>[^/]+)',
        r'https://www.credit-cooperatif.coop/se-connecter/main\..*.js$',
        r'https://www.caisse-epargne.fr/espace-client/main\..*\.js',
        r'https://www.caisse-epargne.fr/gestion-client/credit-immobilier/main\..*\.js',
        r'https://www.caisse-epargne.fr/espace-gestion/pret-personnel/main\..*\.js',
    )
    config_page = CaisseEpargne.config_page.with_urls(r'https://www.credit-cooperatif.coop/ria/pas/configuration/config.json\?ts=(?P<timestamp>.*)')

    LINEBOURSE_BROWSER = LinebourseAPIBrowser
    MARKET_URL = 'https://www.offrebourse.com'

    def has_no_history(self, account):
        return account.type == Account.TYPE_LOAN
