<?php
declare(strict_types=1);
define('ACC_BASE_PATH', __DIR__);
require __DIR__ . '/standalone/bootstrap.php';
require_once ACC_PATH . 'includes/helpers/arag-mizaj.php';
require_once ACC_PATH . 'includes/helpers/arag-expense.php';
require_once ACC_PATH . 'includes/helpers/arag-referral.php';

$base = 'http://localhost/acc-engine/api.php/acc/v1';
$out = [];

$ch = curl_init("$base/public/arag/mizaj/questions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out['questions'] = json_decode(curl_exec($ch), true);
curl_close($ch);

$answers = [];
foreach ( Arag_Mizaj::questions() as $q ) {
    $answers[ $q['id'] ] = $q['options'][0]['id'];
}
$ch = curl_init("$base/public/arag/mizaj/submit");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode(['answers' => $answers, 'session_id' => 'test_v4_' . time()]),
]);
$out['mizaj_submit'] = json_decode(curl_exec($ch), true);
curl_close($ch);

$out['finance'] = Arag_Expense::financial_graph();
$out['referral'] = Arag_Referral::get_or_create(0, '09121111111');

echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
