<?php
$db = \Config\Database::connect();
$pengaturanModel = new \App\Models\PengaturanModel();

$pddiktiUrl = $pengaturanModel->where('pengaturan_key', 'pddikti_url')->first()['pengaturan_value'];
$pddiktiUsername = $pengaturanModel->where('pengaturan_key', 'pddikti_username')->first()['pengaturan_value'];
$pddiktiPassword = $pengaturanModel->where('pengaturan_key', 'pddikti_password')->first()['pengaturan_value'];

$client = \Config\Services::curlrequest();

echo "Getting token...\n";
$response = $client->post($pddiktiUrl, [
    'json' => ['act' => 'GetToken', 'username' => $pddiktiUsername, 'password' => $pddiktiPassword],
    'verify' => false,
    'http_errors' => false
]);
$res = json_decode($response->getBody(), true);
$token = $res['data']['token'];
echo "Token: $token\n";

echo "Getting PTs...\n";
$start = microtime(true);
$resPT = $client->post($pddiktiUrl, [
    'json' => [
        'act' => 'GetPerguruanTinggi',
        'token' => $token,
        'filter' => '', 
        'limit' => 5000 
    ],
    'verify' => false,
    'timeout' => 300,
    'http_errors' => false
]);
$time = microtime(true) - $start;
$ptResult = json_decode($resPT->getBody(), true);
echo "Time taken: $time seconds\n";
echo "Count: " . count($ptResult['data']) . "\n";
