<?php


require_once('Controller/FactoryProducer.php');
require_once('Controller/AbstractFactory.php');
require_once('Object/DataObject.php');
require_once('Model/Queries.php');


$action_type = $_GET['action_type'];
$request_type = $_GET['request_type'];
$functionality_type = $_GET['functionality_type'];

if (isset($_GET['id']))
    $random_id = $_GET['id'];
else {
    $random_id = "0";
}

$dataObject = new DataObject();
$dataObject->setFactoryType("Panel");
$dataObject->setActionType($action_type);
$dataObject->setRequestType($request_type);
$dataObject->setFunctionalityType($functionality_type);
$dataObject->setRandomId($random_id);
$dataObject->setPostData($_POST);
$dataObject->setFileData($_FILES);


$abstractFactory = FactoryProducer::getFactory($dataObject);
$actionFactory = $abstractFactory->getFactoryObject();

$responceObject = null;

if ($dataObject->getActionType() == "retrieve") {
    $responceObject = $actionFactory->retrieve();

    // Utility::DebugObject($actionFactory->retrieve());

} else if ($dataObject->getActionType() == "create") {
    // Utility::DebugObject($actionFactory->create());
    $responceObject = $actionFactory->create();

} else if ($dataObject->getActionType() == "update") {
    // Utility::DebugObject($actionFactory->update());
    $responceObject = $actionFactory->update();

} else if ($dataObject->getActionType() == "delete") {
    // Utility::DebugObject($actionFactory->delete());
    $responceObject = $actionFactory->delete();

}

if ($responceObject != null) {
    echo json_encode($responceObject);
}

// echo json_encode(Utility::utf8ize($responceObject));


?>