# encoding: utf-8
from datetime import datetime

from typing import Dict

from tefcancellationreport.repository import OrderRepository


class TefCancellationReport(object):
    def __init__(
        self,
        order_repository    # type: OrderRepository
    ):
        # type: (...) -> None

        self.order_repository = order_repository

    def get_tef_tenders_by_date(
        self,
        initial_date,   # type: datetime
        end_date        # type: datetime
    ):
        # type: (...) -> Dict

        tenders_by_pos = self.order_repository.get_tef_tenders_by_pos(
            initial_date=initial_date,
            end_date=end_date
        )

        tenders_by_date = {}
        for tenders in tenders_by_pos:
            for date, items in tenders.items():
                if date in tenders_by_date:
                    tenders_by_date[date].extend(items)
                else:
                    tenders_by_date[date] = items

        return tenders_by_date

    def get_card_brands(self):
        # type: () -> Dict

        return self.order_repository.get_card_brands()
