<?php
@ini_set('display_errors','0');
@ini_set('log_errors','1');
error_reporting(E_ALL);
require_once __DIR__ . '/api_common.php';
require_once __DIR__ . '/../auth.php';
require_once __DIR__ . '/../db_bootstrap.php';
require_once __DIR__ . '/../messages_lib.php';

require_login();
$conn = ensure_db(true);
if (function_exists('require_perm')) require_perm('can_manage_messages');

$type = strtolower(trim((string)($_GET['type'] ?? '')));
if (!in_array($type, ['missing_phone','sent','failed'], true)) {
  out(['ok'=>false,'error'=>'نوع التفاصيل غير صالح.'], 400);
}

out([
  'ok'=>true,
  'type'=>$type,
  'rows'=>messages_queue_detail_rows($conn, $type, 300),
]);
