<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

include_once '../config/database.php';
include_once '../objects/agent.php';

$database = new Database();
$db = $database->getConnection();

$agent = new Agent($db);

$data = json_decode(file_get_contents("php://input"));

if (isset($data->id)) {
    $agent->id = $data->id;

    $agent->getOneRow();

    $agent_data = array(
        "id" => $agent->id,
        "agent_name" => $agent->agent_name, 
        "contact_person" => $agent->contact_person,
        "commission" => $agent->commission,
        "phone" => $agent->phone,
        "email" => $agent->email,
        "address" => $agent->address,
        "country" => $agent->country,
        "remark" => $agent->remark,
        "inactive" => $agent->inactive,
    );

    echo json_encode($agent_data);
} else {

    echo json_encode(array("message" => "agent is missing."));
}
?>
