# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import babelfish
import pkg_resources
import logging
from ..exceptions import ProviderNotAvailable, InvalidSubtitle
from ..video import Episode, Movie


logger = logging.getLogger(__name__)

#: Entry point for the providers
PROVIDER_ENTRY_POINT = 'subliminal.providers'

#: Available provider names
PROVIDERS = {entry_point.name.decode('utf-8') for entry_point in pkg_resources.iter_entry_points(PROVIDER_ENTRY_POINT)}


class Provider(object):
    """Base class for providers

    If any configuration is possible for the provider, like credentials, it must take place during instantiation

    :param \*\*kwargs: configuration
    :raise: :class:`~subliminal.exceptions.ProviderConfigurationError` if there is a configuration error

    """
    #: Supported BabelFish languages
    languages = set()

    #: Supported video types
    video_types = (Episode, Movie)

    #: Required hash, if any
    required_hash = None

    def __init__(self, **kwargs):
        pass

    def __enter__(self):
        self.initialize()
        return self

    def __exit__(self, type, value, traceback):  # @ReservedAssignment
        self.terminate()

    def initialize(self):
        """Initialize the provider

        Must be called when starting to work with the provider. This is the place for network initialization