#include "SmfToDataApiImpl.h"
#include "logger.hpp"
#include <nlohmann/json.hpp>
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include <vector>
#include <algorithm> //标准算法头文件
#include "smf_procedure.hpp"
#include "smf.h"
// extern  smf::smf_procedure proc;
extern smf::smf_config smf_cfg;

extern  std::list<UeMsg>  UeMsgList;

namespace oai {
namespace smf_server {
namespace api {
SmfToDataApiImpl::SmfToDataApiImpl(
    std::shared_ptr<Pistache::Rest::Router> rtr, smf::smf_app* smf_app_inst,
    std::string address)
    : SmfToDataApi(rtr),
      m_smf_app(smf_app_inst),
      m_address(address) {}
void SmfToDataApiImpl::uemsg_get_am_data(
    Pistache::Http::ResponseWriter& response) {
     response.headers().add<Pistache::Http::Header::AccessControlAllowOrigin>("*");
        nlohmann::json response_data_json = {};
        nlohmann::json json_array = nlohmann::json::array();
        if (UeMsgList.size()> 0) {
        //if(!UeMsgList.empty())
            int i=0;
            for (std::list<UeMsg>::iterator it = UeMsgList.begin(); it != UeMsgList.end(); it++)
            {
                //std::cout << "ueip " << (*it).ueip << " imsi " << it->imsi << " timestamp： " << it->timestamp << std::endl;
                json_array[i]["imsi"] = it->imsi;
                json_array[i]["ueip"] = (*it).ueip;
                json_array[i]["timestamp"] = it->timestamp;
                i++;
            }
            response_data_json["code"] = 200;
            response_data_json["msg"]= "success";
            response_data_json["data"]= json_array;
        }else{
            response_data_json["code"] = 201;
            response_data_json["msg"]= "没有此数据";
            response_data_json["data"]= NULL;
        }
        try {
            response.send(Pistache::Http::Code::Ok, response_data_json.dump()); 
            return;
        } catch (nlohmann::json::exception &e) {
            response.send(Pistache::Http::Code::Not_Found, response_data_json.dump());
            return;
        }
}


}  // namespace api
}  // namespace smf_server
}  // namespace oai
