import datetime
from dataclasses import dataclass
from typing import List

from ludialudom.resources.base import BaseResource


class Card(BaseResource):

    @dataclass
    class ExpirationItem(object):
        payment_id: str
        name: str
        surname: str
        email: str

    def expirations(self, date: datetime.date) -> List["Card.ExpirationItem"]:
        payload = {
            "date": date.strftime("%Y-%m"),
            "sign": self._sign(date.strftime("%Y-%m"))
        }

        # TODO: check sign
        response = self.requestor.request('GET', '/getListOfExpire', query=payload)

        result = []
        for item in response['listOfExpire']:
            result.append(self.ExpirationItem(
                payment_id=item['paymentId'],
                name=item['name'],
                surname=item['surname'],
                email=item['email']
            ))

        return result
