<?php

namespace Blog\Controller;

use Blog\Model\TicketModel;

class TicketController {

    private $ticketModel;
    private $view;

    public function __construct($view) {
        $this->ticketModel = new TicketModel();
        $this->view = $view;
    }

    public function showTickets() {
        $tickets = $this->ticketModel->getTickets();
        $this->view->setVars(['tickets' => $tickets]);
    }

    public function buyTicket() {
        $data = [
            'userid' => $_POST['userid'],
            'eventid' => $_POST['eventid'],
            'kaufdatum' => date('Y-m-d'),
            'gültigkeitsdatum' => $_POST['gültigkeitsdatum']
        ];
        $erg = $this->ticketModel->buyTicket($data);
        $this->view->setVars(['ticket' => $erg]);
    }

    public function deleteTicket() {
        $ticketid = $_GET['ticketid'] ?? null;
        if ($ticketid) {
            $this->ticketModel->deleteTicket($ticketid);
        }
    }
}