# coding: utf-8

"""
    Knetik Platform API Documentation latest 

    This is the spec for the Knetik API.  Use this in conjunction with the documentation found at https://knetikcloud.com.

    OpenAPI spec version: latest 
    Contact: support@knetik.com
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import sys
import os
import re

# python 2 and python 3 compatibility library
from six import iteritems

from ..api_client import ApiClient


class GamificationLeaderboardsApi(object):
    """
    NOTE: This class is auto generated by the swagger code generator program.
    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def get_leaderboard(self, context_type, context_id, **kwargs):
        """
        Retrieves leaderboard details and paginated entries
        The context type identifies the type of entity (i.e., 'activity') being tracked on the leaderboard. The context ID is the unique ID of the actual entity tracked by the leaderboard. Sorting is based on the fields of LeaderboardEntryResource rather than the returned LeaderboardResource. <br><br><b>Permissions Needed:</b> ANY
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_leaderboard(context_type, context_id, async=True)
        >>> result = thread.get()

        :param async bool
        :param str context_type: The context type for the leaderboard (required)
        :param str context_id: The context id for the leaderboard (required)
        :param int size: The number of objects returned per page
        :param int page: The number of the page returned, starting with 1
        :param str order: A comma separated list of sorting requirements in priority order, each entry matching PROPERTY_NAME:[ASC|DESC]
        :return: LeaderboardResource
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.get_leaderboard_with_http_info(context_type, context_id, **kwargs)
        else:
            (data) = self.get_leaderboard_with_http_info(context_type, context_id, **kwargs)
            return data

    def get_leaderboard_with_http_info(self, context_type, context_id, **kwargs):
        """
        Retrieves leaderboard details and paginated entries
        The context type identifies the type of entity (i.e., 'activity') being tracked on the leaderboard. The context ID is the unique ID of the actual entity tracked by the leaderboard. Sorting is based on the fields of LeaderboardEntryResource rather than the returned LeaderboardResource. <br><br><b>Permissions Needed:</b> ANY
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_leaderboard_with_http_info(context_type, context_id, async=True)
        >>> result = thread.get()

        :param async bool
        :param str context_type: The context type for the leaderboard (required)
        :param str context_id: The context id for the leaderboard (required)
        :param int size: The number of objects returned per page
        :param int page: The number of the page returned, starting with 1
        :param str order: A comma separated list of sorting requirements in priority order, each entry matching PROPERTY_NAME:[ASC|DESC]
        :return: LeaderboardResource
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['context_type', 'context_id', 'size', 'page', 'order']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_leaderboard" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'context_type' is set
        if ('context_type' not in params) or (params['context_type'] is None):
            raise ValueError("Missing the required parameter `context_type` when calling `get_leaderboard`")
        # verify the required parameter 'context_id' is set
        if ('context_id' not in params) or (params['context_id'] is None):
            raise ValueError("Missing the required parameter `context_id` when calling `get_leaderboard`")


        collection_formats = {}

        path_params = {}
        if 'context_type' in params:
            path_params['context_type'] = params['context_type']
        if 'context_id' in params:
            path_params['context_id'] = params['context_id']

        query_params = []
        if 'size' in params:
            query_params.append(('size', params['size']))
        if 'page' in params:
            query_params.append(('page', params['page']))
        if 'order' in params:
            query_params.append(('order', params['order']))

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/leaderboards/{context_type}/{context_id}', 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='LeaderboardResource',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)

    def get_leaderboard_rank(self, context_type, context_id, id, **kwargs):
        """
        Retrieves a specific user entry with rank
        The context type identifies the type of entity (i.e., 'activity') being tracked on the leaderboard. The context ID is the unique ID of the actual entity tracked by the leaderboard. <br><br><b>Permissions Needed:</b> ANY
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_leaderboard_rank(context_type, context_id, id, async=True)
        >>> result = thread.get()

        :param async bool
        :param str context_type: The context type for the leaderboard (required)
        :param str context_id: The context id for the leaderboard (required)
        :param str id: The id of a user (required)
        :return: LeaderboardEntryResource
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.get_leaderboard_rank_with_http_info(context_type, context_id, id, **kwargs)
        else:
            (data) = self.get_leaderboard_rank_with_http_info(context_type, context_id, id, **kwargs)
            return data

    def get_leaderboard_rank_with_http_info(self, context_type, context_id, id, **kwargs):
        """
        Retrieves a specific user entry with rank
        The context type identifies the type of entity (i.e., 'activity') being tracked on the leaderboard. The context ID is the unique ID of the actual entity tracked by the leaderboard. <br><br><b>Permissions Needed:</b> ANY
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_leaderboard_rank_with_http_info(context_type, context_id, id, async=True)
        >>> result = thread.get()

        :param async bool
        :param str context_type: The context type for the leaderboard (required)
        :param str context_id: The context id for the leaderboard (required)
        :param str id: The id of a user (required)
        :return: LeaderboardEntryResource
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['context_type', 'context_id', 'id']
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_leaderboard_rank" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'context_type' is set
        if ('context_type' not in params) or (params['context_type'] is None):
            raise ValueError("Missing the required parameter `context_type` when calling `get_leaderboard_rank`")
        # verify the required parameter 'context_id' is set
        if ('context_id' not in params) or (params['context_id'] is None):
            raise ValueError("Missing the required parameter `context_id` when calling `get_leaderboard_rank`")
        # verify the required parameter 'id' is set
        if ('id' not in params) or (params['id'] is None):
            raise ValueError("Missing the required parameter `id` when calling `get_leaderboard_rank`")


        collection_formats = {}

        path_params = {}
        if 'context_type' in params:
            path_params['context_type'] = params['context_type']
        if 'context_id' in params:
            path_params['context_id'] = params['context_id']
        if 'id' in params:
            path_params['id'] = params['id']

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/leaderboards/{context_type}/{context_id}/users/{id}/rank', 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='LeaderboardEntryResource',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)

    def get_leaderboard_strategies(self, **kwargs):
        """
        Get a list of available leaderboard strategy names
        <b>Permissions Needed:</b> ANY
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_leaderboard_strategies(async=True)
        >>> result = thread.get()

        :param async bool
        :return: list[str]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.get_leaderboard_strategies_with_http_info(**kwargs)
        else:
            (data) = self.get_leaderboard_strategies_with_http_info(**kwargs)
            return data

    def get_leaderboard_strategies_with_http_info(self, **kwargs):
        """
        Get a list of available leaderboard strategy names
        <b>Permissions Needed:</b> ANY
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_leaderboard_strategies_with_http_info(async=True)
        >>> result = thread.get()

        :param async bool
        :return: list[str]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = []
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_leaderboard_strategies" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.\
            select_header_accept(['application/json'])

        # Authentication setting
        auth_settings = ['oauth2_client_credentials_grant', 'oauth2_password_grant']

        return self.api_client.call_api('/leaderboards/strategies', 'GET',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=body_params,
                                        post_params=form_params,
                                        files=local_var_files,
                                        response_type='list[str]',
                                        auth_settings=auth_settings,
                                        async=params.get('async'),
                                        _return_http_data_only=params.get('_return_http_data_only'),
                                        _preload_content=params.get('_preload_content', True),
                                        _request_timeout=params.get('_request_timeout'),
                                        collection_formats=collection_formats)
