<?php

namespace App\Controllers\Admin;

use App\Models\Control\InvoiceModel;
use App\Models\Control\SubscriptionModel;
use App\Models\Control\TenantRecordModel;
use Config\Lookups;

/**
 * Basic platform-wide usage/revenue reporting — one screen, no export,
 * no date-range picker yet. Enough for an operator to see where the
 * platform stands; a proper reporting module (charts, CSV export, date
 * filters) is future work, not part of this slice.
 */
class ReportController extends BaseAdminController
{
    public function index()
    {
        $subscriptions = new SubscriptionModel();
        $invoices      = new InvoiceModel();

        $subsByStatus = [];
        foreach (array_keys((new Lookups())->subscriptionStatuses) as $status) {
            $subsByStatus[$status] = $subscriptions->countByStatus($status);
        }

        $invoicesByStatus = [];
        foreach (array_keys((new Lookups())->invoiceStatuses) as $status) {
            $invoicesByStatus[$status] = $invoices->countByStatus($status);
        }

        return view('admin/reports/index', [
            'pageTitle'         => 'Reports',
            'activeNav'         => 'reports',
            'subsByStatus'      => $subsByStatus,
            'invoicesByStatus'  => $invoicesByStatus,
            'mrr'               => $subscriptions->estimatedMrr(),
            'totalCollected'    => $invoices->totalCollected(),
            'totalOutstanding'  => $invoices->totalOutstanding(),
            'totalHotels'       => (new TenantRecordModel())->countAllResults(),
        ]);
    }
}
