<?php

namespace App\Controllers;

use App\Models\Order;
use App\Models\Domain;
use App\Models\Setting;
use App\Utils\View;

class IntegrationController
{
    public function stats()
    {
        $orderModel = new Order();
        $domainModel = new Domain();
        $settingModel = new Setting();

        // Orders metrics
        $totalOrders = $orderModel->countAll();
        $recentOrders = $orderModel->countRecent(7); // Last 7 days

        // Domain metrics
        $blockedDomains = $domainModel->countBlocked();

        // Last Update - Date of last order
        $lastUpdate = $orderModel->getLastOrderDate();
        if (!$lastUpdate) {
            $lastUpdate = date('Y-m-d H:i:s');
        }

        View::json([
            'orders_total' => $totalOrders,
            'orders_recent' => $recentOrders,
            'domains_blocked' => $blockedDomains,
            'last_update' => $lastUpdate
        ]);
    }
}
