<?php
require __DIR__.'/_bootstrap.php';
use Zoo\Database;
use Zoo\Withdrawal\RaastAgentService;
try{
 $in=input_json();$db=Database::connect();$svc=new RaastAgentService($db);
 $token=(string)($_SERVER['HTTP_X_RAAST_AGENT_TOKEN']??'');
 $agent=$svc->authenticate($token);
 $r=$svc->action(
   (int)$agent['id'],(int)($in['assignment_id']??0),(string)($in['action']??''),
   isset($in['payout_channel'])?(string)$in['payout_channel']:null,
   isset($in['payout_reference'])?(string)$in['payout_reference']:null,
   isset($in['note'])?(string)$in['note']:null
 );
 json_out(['ok'=>true,'result'=>$r]);
}catch(Throwable $e){json_out(['ok'=>false,'error'=>$e->getMessage()],422);}
