# coding: utf-8
from riotpy.resources.match import MatchResource
from base import Manager


class MatchHistoryManager(Manager):
    """
        We are spliting this one and MatchManager because Riot did it.
        That way, our lib is closer to their documentation.
    """

    def get_summoner_match_history(self, summoner_id, begin_index=None, end_index=None,
                                   champion_ids=None, ranked_queues=None):
        """
            Get a summoner match history

            :param summoner_id: The ID of the summoner.
            :param begin_index: The begin index to use for fetching games.
            :param end_index: The end index to use for fetching games.
            :param champion_ids: Comma-separated list of champion IDs to use
                for fetching games.
            :param ranked_queue: Comma-separated list of ranked queue types
                to use for fetching games. Non-ranked queue types will be ignored.
                Ex: riotpy.constants.RankedQueues

            :return: A resources.match.MatchResource list
        """
        extra = {}

        if begin_index:
            try:
                extra['beginIndex'] = int(begin_index)
            except:
                pass
        if end_index:
            try:
                extra['endIndex'] = int(end_index)
            except:
                pass

        if champion_ids:
            extra['championIds'] = champion_ids
        if ranked_queues:
            extra['rankedQueues'] = ranked_queues

        content = self._get('api/lol/{}/{}/matchhistory/{}'.format(
            self.api.region,
            self.version,
            summoner_id), extra=extra
        )
        return self._dict_to_resource(content['matches'], resource_class=MatchResource)
