<?php
declare(strict_types=1);

namespace App\Controller\Admin;

use Cake\ORM\TableRegistry;

class BookingsController extends AdminAppController
{
    public function index(): void
    {
        $bookings = $this->fetchTable('Bookings')->find()
            ->contain(['Teachers', 'AvailabilitySlots'])
            ->orderBy(['Bookings.created' => 'DESC'])
            ->limit(100)
            ->all();

        $metrics = [
            'total' => $this->fetchTable('Bookings')->find()->count(),
            'paid' => $this->fetchTable('Bookings')->find()->where(['status' => 'paid'])->count(),
            'pending' => $this->fetchTable('Bookings')->find()->where(['status' => 'pending'])->count(),
            'cancelled' => $this->fetchTable('Bookings')->find()->where(['status' => 'cancelled'])->count(),
        ];

        $this->set(compact('bookings', 'metrics'));
    }
}
