<?php
$_SERVER['REMOTE_ADDR'] = '103.91.52.108';
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/includes/ProxyHelper.php';
$helper = new ProxyHelper();
$ubrn = '20082692068091735';

$extraHeaders = [
    'X-Requested-With: XMLHttpRequest',
    'Accept: application/json, text/javascript, */*; q=0.01'
];
$csrf = $helper->getCsrfToken();
if ($csrf) {
    $extraHeaders[] = 'X-CSRF-TOKEN: ' . $csrf;
}

$urls = [
    'bdris_register_search' => "https://bdris.gov.bd/api/br/register/search/by-ubrn?ubrn=" . urlencode($ubrn),
    'bdris_search_by_ubrn' => "https://bdris.gov.bd/api/br/search-by-ubrn?ubrn=" . urlencode($ubrn),
    'everify_info' => "https://everify.bdris.gov.bd/api/br/info/ubrn/" . urlencode($ubrn),
    'everify_register_search' => "https://everify.bdris.gov.bd/api/br/register/search/by-ubrn?ubrn=" . urlencode($ubrn),
    'bdris_parent_proj' => "https://bdris.gov.bd/api/br/parent-projection-by-ubrn?ubrn=" . urlencode($ubrn),
    'bdris_person_info_dg1' => "https://bdris.gov.bd/api/br/info/person-info-by-ubrn-and-data-group?ubrn=" . urlencode($ubrn) . "&dataGroup=1",
    'bdris_person_info_nationality' => "https://bdris.gov.bd/api/br/info/person-info-with-nationality-by-ubrn-and-data-group?ubrn=" . urlencode($ubrn) . "&dataGroup=1",
    'bdris_person_name_en_bn' => "https://bdris.gov.bd/api/br/info/person-name-en-bn-pair-by-ubrn?ubrn=" . urlencode($ubrn),
];

$results = [];
foreach ($urls as $key => $url) {
    $referer = strpos($url, 'everify') !== false ? 'https://everify.bdris.gov.bd/' : 'https://bdris.gov.bd/admin/br/search';
    $res = $helper->fetch($url, 'GET', [], false, $referer, $extraHeaders);
    $results[$key] = [
        'status' => $res['status'],
        'body' => json_decode($res['body'], true) ?: substr($res['body'], 0, 500)
    ];
}

echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
