#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi <gogogo.vm@gmail.com>
"""

from __future__ import absolute_import

from ._table_extractor import (
    SqliteSchemaTableExtractorV0,
    SqliteSchemaTableExtractorV1,
)
from ._text_extractor import (
    SqliteSchemaTextExtractorV0,
    SqliteSchemaTextExtractorV1,
    SqliteSchemaTextExtractorV2,
    SqliteSchemaTextExtractorV3,
    SqliteSchemaTextExtractorV4,
    SqliteSchemaTextExtractorV5,
)


class SqliteSchemaExtractorFactory(object):

    @property
    def min_verbosity_level(self):
        return min(self.__extractor_mapping)

    @property
    def max_verbosity_level(self):
        return max(self.__extractor_mapping)

    def __init__(self, database_path, extractor_mapping):
        self.__database_path = database_path
        self.__extractor_mapping = extractor_mapping

    def create(self, verbosity_level=None):
        verbosity_level = self._clip_verbosity_level(verbosity_level)

        return self.__extractor_mapping.get(verbosity_level)(
            self.__database_path)

    def _clip_verbosity_level(self, verbosity_level):
        if verbosity_level is None:
            return self.max_verbosity_level

        if verbosity_level < self.min_verbosity_level:
            return self.min_verbosity_level

        if verbosity_level > self.max_verbosity_level:
            return self.max_verbosity_level

        return verbosity_level


class SqliteSchemaTextExtractorFactory(SqliteSchemaExtractorFactory):

    def __init__(self, database_path):
        super(SqliteSchemaTextExtractorFactory, self).__init__(
            database_path,
            {
                0: SqliteSchemaTextExtractorV0,
                1: SqliteSchemaTextExtractorV1,
                2: SqliteSchemaTextExtractorV2,
                3: SqliteSchemaTextExtractorV3,
                4: SqliteSchemaTextExtractorV4,
                5: SqliteSchemaTextExtractorV5,
            })


class SqliteSchemaTableExtractorFactory(SqliteSchemaExtractorFactory):

    def __init__(self, database_path):
        super(SqliteSchemaTableExtractorFactory, self).__init__(
            database_path,
            {
                0: SqliteSchemaTableExtractorV0,
                1: SqliteSchemaTableExtractorV1,
            })

@@ -741,20 +741,22 @@
 atabase_
-path
+source
 , extrac
@@ -793,20 +793,22 @@
 atabase_
-path
+source
  = datab
@@ -811,20 +811,22 @@
 atabase_
-path
+source
 %0A       
@@ -1077,20 +1077,22 @@
 atabase_
-path
+source
 )%0A%0A    d
@@ -1549,36 +1549,38 @@
 (self, database_
-path
+source
 ):%0A        super
@@ -1643,36 +1643,38 @@
        database_
-path
+source
 ,%0A            %7B%0A
@@ -2082,20 +2082,22 @@
 atabase_
-path
+source
 ):%0A     
@@ -2181,12 +2181,14 @@
 ase_
-path
+source
 ,%0A  

Rename arguments