<?php
require __DIR__.'/_bootstrap.php';

use Zoo\Database;
use Zoo\Admin\AdminApiAuth;

try{
    AdminApiAuth::requireKey();
    $db=Database::connect();

    $q=$db->query("
      SELECT d.id,d.user_id,d.reference,d.method,d.amount,d.status,
             d.payer_reference,d.submitted_at,d.created_at,d.updated_at,
             u.public_id
      FROM player_deposits d
      LEFT JOIN users u ON u.id=d.user_id
      WHERE d.status='pending'
      ORDER BY (d.submitted_at IS NULL) ASC,d.submitted_at ASC,d.id ASC
      LIMIT 200
    ");

    json_out(['ok'=>true,'deposits'=>$q->fetchAll(PDO::FETCH_ASSOC)]);
}catch(Throwable $e){
    json_out(['ok'=>false,'error'=>$e->getMessage()],403);
}
