<?php

declare(strict_types=1);

require_once __DIR__ . '/../includes/api_client.php';

$tests = [
    ['email' => 'admin', 'password' => '123456'],
    ['login_id' => 'admin', 'password' => '123456'],
    ['username' => 'admin', 'password' => '123456'],
];

foreach ($tests as $payload) {
    $config = api_config();
    $url = rtrim((string)$config['base_url'], '/') . ($config['endpoints']['login'] ?? '/karvipartner/login');

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Accept: application/json'],
        CURLOPT_POSTFIELDS => json_encode($payload),
        CURLOPT_TIMEOUT => 20,
    ]);

    $raw = curl_exec($ch);
    $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    echo 'Payload: ' . json_encode($payload) . PHP_EOL;
    echo 'Status: ' . $status . PHP_EOL;
    echo 'Response: ' . (is_string($raw) ? $raw : 'curl failed') . PHP_EOL . PHP_EOL;
}
