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

"""
ctddocumentation

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from apimatic_core.configurations.global_configuration import GlobalConfiguration
from apimatic_core.decorators.lazy_property import LazyProperty
from ctddocumentation.configuration import Configuration
from ctddocumentation.controllers.base_controller import BaseController
from ctddocumentation.configuration import Environment
from ctddocumentation.http.auth.custom_header_authentication import CustomHeaderAuthentication
from ctddocumentation.controllers.login_controller import LoginController
from ctddocumentation.controllers.assets_controller import AssetsController
from ctddocumentation.controllers.alerts_controller import AlertsController
from ctddocumentation.controllers.tasks_controller import TasksController
from ctddocumentation.controllers.tasks_queries_controller\
    import TasksQueriesController
from ctddocumentation.controllers.queries_controller import QueriesController
from ctddocumentation.controllers.insights_controller import InsightsController
from ctddocumentation.controllers.sites_controller import SitesController
from ctddocumentation.controllers.activities_controller\
    import ActivitiesController
from ctddocumentation.controllers.license_controller import LicenseController
from ctddocumentation.controllers.users_controller import UsersController
from ctddocumentation.controllers.groups_controller import GroupsController
from ctddocumentation.controllers.sensors_controller import SensorsController
from ctddocumentation.controllers.custom_attributes_categories_controller\
    import CustomAttributesCategoriesController
from ctddocumentation.controllers.events_controller import EventsController


class CtddocumentationClient(object):

    @LazyProperty
    def login(self):
        return LoginController(self.global_configuration)

    @LazyProperty
    def assets(self):
        return AssetsController(self.global_configuration)

    @LazyProperty
    def alerts(self):
        return AlertsController(self.global_configuration)

    @LazyProperty
    def tasks(self):
        return TasksController(self.global_configuration)

    @LazyProperty
    def tasks_queries(self):
        return TasksQueriesController(self.global_configuration)

    @LazyProperty
    def queries(self):
        return QueriesController(self.global_configuration)

    @LazyProperty
    def insights(self):
        return InsightsController(self.global_configuration)

    @LazyProperty
    def sites(self):
        return SitesController(self.global_configuration)

    @LazyProperty
    def activities(self):
        return ActivitiesController(self.global_configuration)

    @LazyProperty
    def license(self):
        return LicenseController(self.global_configuration)

    @LazyProperty
    def users(self):
        return UsersController(self.global_configuration)

    @LazyProperty
    def groups(self):
        return GroupsController(self.global_configuration)

    @LazyProperty
    def sensors(self):
        return SensorsController(self.global_configuration)

    @LazyProperty
    def custom_attributes_categories(self):
        return CustomAttributesCategoriesController(self.global_configuration)

    @LazyProperty
    def events(self):
        return EventsController(self.global_configuration)

    def __init__(self, http_client_instance=None,
                 override_http_client_configuration=False, http_call_back=None,
                 timeout=60, max_retries=0, backoff_factor=2,
                 retry_statuses=[408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
                 retry_methods=['GET', 'PUT'],
                 environment=Environment.PRODUCTION, host='HostValue',
                 authorization='TODO: Replace', config=None):
        if config is None:
            self.config = Configuration(
                                         http_client_instance=http_client_instance,
                                         override_http_client_configuration=override_http_client_configuration,
                                         http_call_back=http_call_back,
                                         timeout=timeout,
                                         max_retries=max_retries,
                                         backoff_factor=backoff_factor,
                                         retry_statuses=retry_statuses,
                                         retry_methods=retry_methods,
                                         environment=environment, host=host,
                                         authorization=authorization)
        else:
            self.config = config

        self.global_configuration = GlobalConfiguration(self.config)\
            .global_errors(BaseController.global_errors())\
            .base_uri_executor(self.config.get_base_uri)\
            .user_agent(BaseController.user_agent(), BaseController.user_agent_parameters())
        self.initialize_auth_managers(self.global_configuration)

        self.global_configuration = self.global_configuration.auth_managers(self.auth_managers)

    def initialize_auth_managers(self, global_config):
        http_client_config = global_config.get_http_client_configuration()
        self.auth_managers = { key: None for key in ['global']}
        self.auth_managers['global'] = CustomHeaderAuthentication(http_client_config.authorization)
        return self.auth_managers
