use sensor\Define;
use sensor\config\Config;
// ----------------------------------------------------------------------------
$app = Config::configure(new Application());
// Application Name
$app->setName('sensor-viewer');
//
// Rest Action GET: /viewer/hello
//
$app->get('/hello', function () use($app) {
    $result = array('status' => Define::RESULT_OKAY, 'message' => 'Hello World, I am the viewer', 'target' => '<%= target %>', 'version' => '<%= version %>');
    $app->sendResult($result);
});
//
// Rest Action GET: /viewer/info
//
$app->get('/info', function () use($app) {
    $provider = new SensorProvider($app);
    $provider->sendInfo();
});
//
// catch errors
//
$app->error(function (\Exception $e) use($app) {
    $result = array('status' => Define::RESULT_OKAY, 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTraceAsString());
    $app->sendResult($result, 400);
});
//
// Execution
//
$app->run();
// Rest Action GET: /viewer/hello
//
$app->get('/hello', function () use($app) {
    $result = array('status' => Define::RESULT_OKAY, 'message' => 'Hello World, I am the viewer', 'target' => '<%= target %>', 'version' => '<%= version %>');
    $app->sendResult($result);
});
//
// Rest Action GET: /viewer/info
//
$app->get('/info', function () use($app) {
    $provider = new SensorProvider($app);
    $provider->sendInfo();
});
//
// Rest Action GET: /viewer/sensor/:id
//
$app->get('/sensor/:id', function ($id) use($app) {
    $provider = new SensorProvider($app);
    $provider->sendSensor($id);
});
//
// catch errors
//
$app->error(function (\Exception $e) use($app) {
    $result = array('status' => Define::RESULT_OKAY, 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTraceAsString());
    $app->sendResult($result, 400);
});
//
// Execution
//
$app->run();