<?php

namespace Modules\Appointments\Controllers;

use core\Controller;
use core\Auth;
use core\Database;
use core\Session;
use core\Security;
use Modules\Appointments\Models\Appointment;

class CalendarController extends Controller
{
    private Appointment $appointmentModel;

    public function __construct()
    {
        parent::__construct();
        $this->appointmentModel = new Appointment();
    }

    public function index(): void
    {
        $this->requirePermission('appointments_view');

        $this->view('Appointments/calendar', [
            'title' => 'Calendar',
            'breadcrumb' => [
                'Appointments' => url('appointments'),
                'Calendar' => url('appointments/calendar'),
            ],
        ]);
    }

    public function events(): void
    {
        $this->requirePermission('appointments_view');

        $start = $this->request->get('start', date('Y-m-01'));
        $end = $this->request->get('end', date('Y-m-t'));

        $events = $this->appointmentModel->getCalendarEvents($start, $end);

        $this->json($events);
    }
}
