/**
* Namf_Communication
* AMF Communication Service © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved. 
*
* The version of the OpenAPI document: 1.1.0.alpha-1
* 
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

#include "N1N2MessageCollectionDocumentApi.h"
#include "Helpers.h"

namespace oai {
namespace amf {
namespace api {

using namespace org::openapitools::server::helpers;
using namespace oai::amf::model;

N1N2MessageCollectionDocumentApi::N1N2MessageCollectionDocumentApi(std::shared_ptr<Pistache::Rest::Router> rtr) { 
    router = rtr;
}

void N1N2MessageCollectionDocumentApi::init() {
    setupRoutes();
}

void N1N2MessageCollectionDocumentApi::setupRoutes() {
    using namespace Pistache::Rest;

    Routes::Post(*router, base + "/ue-contexts/:ueContextId/n1-n2-messages", Routes::bind(&N1N2MessageCollectionDocumentApi::n1_n2_message_transfer_handler, this));

    // Default handler, called when a route is not found
    router->addCustomHandler(Routes::bind(&N1N2MessageCollectionDocumentApi::n1_n2_message_collection_document_api_default_handler, this));
}

void N1N2MessageCollectionDocumentApi::n1_n2_message_transfer_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
    // Getting the path params
    auto ueContextId = request.param(":ueContextId").as<std::string>();
    std::cout <<"Received a N1N2MessageTrasfer request with ueID " << ueContextId.c_str()<<std::endl;
    
    // Getting the body param
    //N1N2MessageTransferReqData n1N2MessageTransferReqData;
    nlohmann::json response_data;
    response_data["cause"] = "N1_N2_TRANSFER_INITIATED";
    response_data.dump().c_str();
    response.headers().add<Pistache::Http::Header::ContentType>(Pistache::Http::Mime::MediaType("application/json"));
    response.send(Pistache::Http::Code::Ok, response_data.dump().c_str());


  /*
    try {
      nlohmann::json::parse(request.body()).get_to(n1N2MessageTransferReqData);
      this->n1_n2_message_transfer(ueContextId, n1N2MessageTransferReqData, response);
    } catch (nlohmann::detail::exception &e) {
        //send a 400 error
        response.send(Pistache::Http::Code::Bad_Request, e.what());
        return;
    } catch (std::exception &e) {
        //send a 500 error
        response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
        return;
    }
*/

}

void N1N2MessageCollectionDocumentApi::n1_n2_message_collection_document_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
    response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}

}
}
}

