<?php
/**
 * User: tec
 * Date: 05/09/14
 * Time: 10:55
 */

/* GET    - Read requests 
 * POST   - Create data
 * PUT    - Modify existing data
 * DELETE - Remove data
 */

session_start();

// Include the API
require_once('../classes/api.php');
require_once('api-flight.php');
require_once('api-flightproject.php');
require_once('api-project.php');
require_once('api-pi.php');
require_once('api-flightsensor.php');
require_once('api-sensorstatus.php');


// Check for variable
if(!isset($_GET['request'])) {
   // Exit
   die();
}

/* Flight ID Regex: [0-9]+
 * Project Code Regex: [A-Z]+[0-9]*[/-]?[0-9\-]*
 * PI ID Regex: [0-9]+
 * Flight Sensor ID Regex: [0-9]+
 * Sensor Status ID Regex: [0-9]+
 * */

// Init api
$api = new API();

// Add routes to api

// EDIT PAGE ROUTES
// Flight info routes
$api->route('GET', '@edit/flight/([0-9]+)@', new GetFlightInfo(), true);
$api->route('PUT', '@edit/flight/([0-9]+)@', new UpdateFlight(), true);
$api->route('DELETE', '@edit/flight/([0-9]+)@', new DeleteFlight(), true);

// Flight project routes
$api->route('PUT', '@edit/flightproject/([0-9]+)@', new UpdateFlightProject(), true);
$api->route('POST', '@edit/flightproject/([0-9]+)/([A-Z]+[0-9]*[/-]?[0-9\-]*)@', new InsertFlightProject(), true);

// Project info routes
$api->route('GET', '@edit/project/([0-9]+)@', new GetProjectInfo(), true);
$api->route('PUT', '@edit/project/([A-Z]+[0-9]*[/-]?[0-9\-]*)@', new UpdateProject(), true);
$api->route('DELETE', '@edit/project/([0-9]+)/([A-Z]+[0-9]*[/-]?[0-9\-]*)@', new DeleteProject(), true);

// Pi info routes
$api->route('GET', '@edit/pi/([0-9]+)@', new GetPiInfo(), true);
$api->route('PUT', '@edit/pi/([0-9]+)@', new UpdatePi(), true);

// Flight sensor routes
$api->route('GET', '@edit/flightsensor/([0-9]+)@', new GetFlightSensorInfo(), true);
$api->route('POST', '@edit/flightsensor/([0-9]+)@', new InsertFlightSensor(), true);
$api->route('DELETE', '@edit/flightsensor/([0-9]+)@', new DeleteFlightSensor(), true);
$api->route('PUT', '@edit/flightsensor/([0-9]+)@', new UpdateFlightSensor(), true);

// Sensor Status
$api->route('GET', '@edit/sensorstatus/([0-9]+)@', new GetSensorStatuses(), true);
$api->route('POST', '@edit/sensorstatus/([0-9]+)@', new InsertSensorStatus(), true);
$api->route('PUT', '@edit/sensorstatus@', new UpdateSensorStatus(), true);
$api->route('DELETE', '@edit/sensorstatus/([0-9]+)@', new DeleteSensorStatus(), true);

// ADDFLIGHT PAGE ROUTES
$api->route('GET', '@addflight/pi/([A-Z]+[0-9]*[/-]?[0-9\-]*)@', new GetPiFromProject(), true);
$api->route('POST', '@addflight/flight/?@', new InsertFlight(), true);
$api->route('POST', '@addflight/project/?@', new InsertProject(), true);


// PROGRESS PAGE ROUTES
$api->route('GET', '@progress/flight/([0-9]+)@', new GetProgressFlightInfo(), false);
$api->route('GET', '@progress/flightsensor/([0-9]+)@', new GetProgressFlightSensorInfo(), false);


// Get data
$api->process_route($_GET['request']);

