import requests

from pagerduty_api.abstract_client import AbstractClient
from typing import Any, Dict, List
from pagerduty_api.utils import is_service_name_compliant


class PagerDutyIncidentsClient(AbstractClient):
    def __init__(
        self,
        http_session: requests.Session = requests.Session(),
        endpoint: str = 'https://api.pagerduty.com',
        auth_token: str = None
    ):
        super().__init__(http_session, endpoint, auth_token)
        self._default_url = f'{self._endpoint}/incidents'
        self._default_entity_name = 'incidents'

    def list_incidents(
        self,
        limit: int = 100,
        params: Dict[str, Any] = {},
        paginate: bool = True
    ):
        '''
        >>> import os
        >>> client = PagerDutyIncidentsClient(auth_token=os.environ.get('AUTH_TOKEN'))
        >>> incidents = client.list_incidents()
        Executing HTTP get on https://api.pagerduty.com/incidents
        >>> len(incidents) >= 1
        True
        '''
        if not params:
            params = {
                'query': '',
                'sort_by': 'name',
                'limit': limit,
            }
        params['limit'] = params.get('limit', limit)
        return self.do_request(
            url=self._default_url,
            entity_name=self._default_entity_name,
            params=params,
            paginate=paginate
        )

    