<?php

declare(strict_types=1);

namespace App\Models;

use App\Core\Model;

/**
 * Callback Request Model
 *
 * Handles callback requests from the website popup.
 */
class CallbackRequest extends Model
{
    protected string $table = 'callback_requests';

    /**
     * Get all pending callbacks.
     *
     * @return array<int, array<string, mixed>>
     */
    public function getPending(): array
    {
        return $this->where('status', 'pending');
    }

    /**
     * Count pending callbacks.
     *
     * @return int
     */
    public function countPending(): int
    {
        $sql = "SELECT COUNT(*) AS total FROM `{$this->table}` WHERE status = 'pending'";
        $stmt = $this->db->prepare($sql);
        $stmt->execute();
        return (int) ($stmt->fetch()['total'] ?? 0);
    }
}
