<?php

require_once BASE_PATH . '/app/controllers/admin/AdminBaseController.php';
require_once BASE_PATH . '/app/models/User.php';
require_once BASE_PATH . '/app/models/Post.php';

class AdminDashboardController extends AdminBaseController
{
    private User $userModel;
    private Post $postModel;

    public function __construct()
    {
        parent::__construct();
        $this->requireAdmin();
        $this->userModel = new User();
        $this->postModel = new Post();
    }

    public function index(): void
    {
        $stats = [
            'users' => $this->userModel->countForAdmin(),
            'customers' => $this->userModel->countByRole('customer'),
            'owners' => $this->userModel->countByRole('owner'),
            'admins' => $this->userModel->countByRole('admin'),
            'active_users' => $this->userModel->countByStatus('active'),
            'locked_users' => $this->userModel->countByStatus('locked'),
            'posts' => $this->postModel->countForOwner()
        ];
        $recentUsers = $this->userModel->getRecentForAdmin();
        $recentLogs = $this->activityLog()->getForAdmin('', '', 0, 8);

        require BASE_PATH . '/app/views/admin/dashboard.php';
    }
}
