from classes.Ticket import Ticket
import config
import requests
from typing import List
from requests.models import Response

class TicketRequester:
    def __init__(self, token: str):
        self.token = token


    def patch(self, ticket: Ticket, data: dict) -> Response:
        """ Частичное обновление тикета """
        url: str = config.API_URL + f"tickets/api/v2/ticket/{ticket.id}"
        headers = {'Authorization': f'Api-Key {self.token}'}
        response = requests.patch(url, json=data, headers=headers)
        return response


    def all(self, params: dict = {}) -> List[Ticket]:
        """ Получение всех тикетов """
        url: str = config.API_URL + "tickets/api/v2/ticket/"
        headers = {'Authorization': f'Api-Key {self.token}'}
        response = requests.get(url, headers=headers, params=params)
        return list(map(lambda x: Ticket(**x), response.json()))


    def put(self, ticket: Ticket, data: dict) -> Ticket:
        """ Обновление тикета """
        None


    def post(self, ticket: Ticket, data: dict) -> Ticket:
        """ Создание тикета """
        None


    def delete(self, ticket: Ticket) -> Ticket:
        """ Удаление тикета """
        None
