import logging
import requests

from pagerduty_api import log_it
from pagerduty_api.abstract_client import AbstractClient


class PagerDutyOnCallsClient(AbstractClient):

    def __init__(
        self,
        http_session: requests.Session = requests.Session(),
        endpoint: str = 'https://api.pagerduty.com',
        auth_token: str = None,
        logger: logging.Logger = None
    ):
        super().__init__(http_session, endpoint, auth_token, logger)
        self._default_url = f'{self._endpoint}/oncalls'
        self._default_entity_name = 'oncalls'

    @log_it
    def get_on_call_for_team(self, escalation_policy_id: str):
        '''
        >>> import os
        >>> client = PagerDutyOnCallsClient(auth_token=os.environ.get('AUTH_TOKEN'))
        >>> on_call = client.get_on_call_for_team('PCCNTY7')
        Executing HTTP get on https://api.pagerduty.com/oncalls
        >>> len(on_call) > 0
        True
        '''
        assert escalation_policy_id, f'Cannot get on call for team with escalation policy id: {escalation_policy_id}'
        return self.do_request(
            url=self._default_url,
            entity_name=self._default_entity_name,
            params={
                'time_zone': 'UTC',
                'escalation_policy_ids[]': escalation_policy_id
            }
        )
