<?php
declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;

final class AdminEmailQueueTenantController extends Controller
{
    public function index(): void
    {
        require_org_admin();
        require_org_context();

        $db=Database::getInstance();
        $orgId=(int)current_org_id();

        // email_queue schema: to_email, subject_line, status, created_at
        $st=$db->prepare("
          SELECT id,to_email,to_name,template_key,subject_line,status,error_message,created_at,sent_at
          FROM email_queue
          WHERE org_id=:o
          ORDER BY id DESC
          LIMIT 300
        ");
        $st->execute([':o'=>$orgId]);
        $rows=$st->fetchAll()?:[];

        $this->view('admin/email_queue/index',['rows'=>$rows]);
    }
}
