<?php
declare(strict_types=1);
$base = 'http://localhost/acc-engine/api.php/acc/v1';
$ch = curl_init( "$base/public/auth/login" );
curl_setopt_array( $ch, [
    CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [ 'Content-Type: application/json' ],
    CURLOPT_POSTFIELDS => json_encode( [ 'username' => 'svc_supplier_demo', 'password' => 'SvcReward@1404' ] ),
] );
$auth = json_decode( (string) curl_exec( $ch ), true );
curl_close( $ch );
$token = $auth['token'] ?? '';
$out = [ 'auth_ok' => (bool) $token ];
foreach ( [ 'service/supplier/me', 'service/supplier/catalog', 'service/supplier/orders/open' ] as $path ) {
    $ch = curl_init( "$base/$path" );
    curl_setopt_array( $ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [ "Authorization: Bearer $token" ],
    ] );
    $r = json_decode( (string) curl_exec( $ch ), true );
    curl_close( $ch );
    $out[ $path ] = [
        'ok'    => ! empty( $r['success'] ),
        'count' => is_array( $r['data'] ?? null ) ? count( $r['data'] ) : null,
        'code'  => $r['code'] ?? null,
        'msg'   => $r['message'] ?? null,
    ];
}
echo json_encode( $out, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT );
