<?php
class BillingController {
    private $db;
    public function __construct() { $this->db = Database::getInstance(); }

    public function index() {
        $cid = Auth::user()['company_id'];
        $subscription = $this->db->fetch("SELECT s.*, sp.name as plan_name, sp.price, sp.max_units, sp.max_users, sp.features FROM subscriptions s JOIN subscription_plans sp ON s.plan_id=sp.id WHERE s.company_id=? ORDER BY s.created_at DESC LIMIT 1", [$cid]);
        $plans = $this->db->fetchAll("SELECT * FROM subscription_plans WHERE is_active=1 ORDER BY price");
        $usage = [
            'units' => $this->db->fetchColumn("SELECT COUNT(*) FROM units WHERE company_id=? AND deleted_at IS NULL", [$cid]),
            'users' => $this->db->fetchColumn("SELECT COUNT(*) FROM users WHERE company_id=? AND deleted_at IS NULL", [$cid]),
        ];
        require 'app/views/billing/index.php';
    }
}
