from .base_api import BaseAPI
from .team_profile import TeamProfile

class Team(BaseAPI):
    """Follows the Slack Team API. See https://api.slack.com/methods"""

    def __init__(self, *args, **kwargs):
        super(Team, self).__init__(*args, **kwargs)
        self._profile = TeamProfile(*args, **kwargs)

    @property
    def profile(self):
        return self._profile

    def info(self):
        """
        Gets information about the current team

        :return: A response object to run the API request.
        :rtype: :class:`Response <Response>` object
        """
        return self.get('team.info')

    def access_logs(self, count=None, page=None, before=None):
        """
        Gets the access log for the current team

        :param count: Number of items to return in the page
        :type count: int
        :param page: The page number of results
        :type page: int
        :param before: End time range of logs to include
        :type before: int
        :return: A response object to run the API request.
        :rtype: :class:`Response <Response>` object
        """
        return self.get('team.accessLogs',
                        params={
                            'count': count,
                            'page': page,
                            'before': before
                        })

    def integration_logs(self, service_id=None, app_id=None, user=None,
                         change_type=None, count=None, page=None):
        """
        Gets the integration logs for the current team

        :param service_id: Filter logs to this service
        :type service_id: str
        :param app_id: Filter logs to this slack app
        :type app_id: str
        :param user: Filter logs generated by this user
        :type user: str
        :param change_type: Filter logs to this change type
        :type change_type: str
        :param count: Number of items to return per page
        :type count: int
        :param page: The page number of results
        :type page: int
        :return: A response object to run the API request.
        :rtype: :class:`Response <Response>` object
        """
        return self.get('team.integrationLogs',
                        params={
                            'service_id': service_id,
                            'app_id': app_id,
                            'user': user,
                            'change_type': change_type,
                            'count': count,
                            'page': page,
                        })

    def billable_info(self, user=None):
        """
        Gets billable users information

        :param user:
        :type user:
        :return: A response object to run the API request.
        :rtype: :class:`Response <Response>` object
        """
        return self.get('team.billableInfo', params={'user': user})

