/**
 * Nudr_DataRepository API OpenAPI file
 * Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB,
 * ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
 *
 * The version of the OpenAPI document: 2.1.2
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator
 * (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
 * the class manually.
 */

#include "AccessAndMobilitySubscriptionDataDocumentApiImpl.h"

namespace org {
namespace openapitools {
namespace server {
namespace api {

using namespace org::openapitools::server::model;

AccessAndMobilitySubscriptionDataDocumentApiImpl::
    AccessAndMobilitySubscriptionDataDocumentApiImpl(
        std::shared_ptr<Pistache::Rest::Router> rtr, MYSQL *mysql)
    : AccessAndMobilitySubscriptionDataDocumentApi(rtr) {
  mysql_WitcommUDRDB = mysql;
}

void AccessAndMobilitySubscriptionDataDocumentApiImpl::query_am_data(
    const std::string &ueId, const std::string &servingPlmnId,
    const Pistache::Optional<std::vector<std::string>> &fields,
    const Pistache::Optional<std::string> &supportedFeatures,
    const Pistache::Optional<Pistache::Http::Header::Raw> &ifNoneMatch,
    const Pistache::Optional<Pistache::Http::Header::Raw> &ifModifiedSince,
    Pistache::Http::ResponseWriter &response) {
  MYSQL_RES *res = NULL;
  MYSQL_ROW row;
  MYSQL_FIELD *field = nullptr;

  nlohmann::json j;

  AccessAndMobilitySubscriptionData accessandmobilitysubscriptiondata;
  const std::string query =
      "select * from AccessAndMobilitySubscriptionData WHERE ueid=" + ueId;

  if (mysql_real_query(mysql_WitcommUDRDB, query.c_str(),
                       (unsigned long)query.size())) {
    std::cout << "mysql_real_query failure！" << std::endl;
    return;
  }

  res = mysql_store_result(mysql_WitcommUDRDB);
  if (res == NULL) {
    std::cout << "mysql_store_result failure！" << std::endl;
    return;
  }

  row = mysql_fetch_row(res);

  if (row != NULL) {
    for (int i = 0; field = mysql_fetch_field(res); i++) {
      if (!strcmp("supportedFeatures", field->name) && row[i] != NULL) {
        accessandmobilitysubscriptiondata.setSupportedFeatures(row[i]);
      } else if (!strcmp("gpsis", field->name) && row[i] != NULL) {
        std::vector<std ::string> gpsis;
        nlohmann::json::parse(row[i]).get_to(gpsis);
        accessandmobilitysubscriptiondata.setGpsis(gpsis);
      } else if (!strcmp("internalGroupIds", field->name) && row[i] != NULL) {
        std::vector<std ::string> internalgroupids;
        nlohmann::json::parse(row[i]).get_to(internalgroupids);
        accessandmobilitysubscriptiondata.setInternalGroupIds(internalgroupids);
      } else if (!strcmp("sharedVnGroupDataIds", field->name) &&
                 row[i] != NULL) {
        std::map<std ::string, std::string> sharedvngroupdataids;
        nlohmann::json::parse(row[i]).get_to(sharedvngroupdataids);
        accessandmobilitysubscriptiondata.setSharedVnGroupDataIds(
            sharedvngroupdataids);
      } else if (!strcmp("subscribedUeAmbr", field->name) && row[i] != NULL) {
        AmbrRm subscribedueambr;
        nlohmann::json::parse(row[i]).get_to(subscribedueambr);
        accessandmobilitysubscriptiondata.setSubscribedUeAmbr(subscribedueambr);
      } else if (!strcmp("nssai", field->name) && row[i] != NULL) {
        Nssai nssai;
        nlohmann::json::parse(row[i]).get_to(nssai);
        accessandmobilitysubscriptiondata.setNssai(nssai);
      } else if (!strcmp("ratRestrictions", field->name) && row[i] != NULL) {
        std ::vector<RatType> ratrestrictions;
        nlohmann::json::parse(row[i]).get_to(ratrestrictions);
        accessandmobilitysubscriptiondata.setRatRestrictions(ratrestrictions);
      } else if (!strcmp("forbiddenAreas", field->name) && row[i] != NULL) {
        std ::vector<Area> forbiddenareas;
        nlohmann::json::parse(row[i]).get_to(forbiddenareas);
        accessandmobilitysubscriptiondata.setForbiddenAreas(forbiddenareas);
      } else if (!strcmp("serviceAreaRestriction", field->name) &&
                 row[i] != NULL) {
        ServiceAreaRestriction servicearearestriction;
        nlohmann::json::parse(row[i]).get_to(servicearearestriction);
        accessandmobilitysubscriptiondata.setServiceAreaRestriction(
            servicearearestriction);
      } else if (!strcmp("coreNetworkTypeRestrictions", field->name) &&
                 row[i] != NULL) {
        std ::vector<CoreNetworkType> corenetworktyperestrictions;
        nlohmann::json::parse(row[i]).get_to(corenetworktyperestrictions);
        accessandmobilitysubscriptiondata.setCoreNetworkTypeRestrictions(
            corenetworktyperestrictions);
      } else if (!strcmp("rfspIndex", field->name) && row[i] != NULL) {
        std::string s = row[i];
        std::stringstream ss;
        int32_t a;
        ss << s;
        ss >> a;
        accessandmobilitysubscriptiondata.setRfspIndex(a);
      } else if (!strcmp("subsRegTimer", field->name) && row[i] != NULL) {
        std::string s = row[i];
        std::stringstream ss;
        int32_t a;
        ss << s;
        ss >> a;
        accessandmobilitysubscriptiondata.setSubsRegTimer(a);
      } else if (!strcmp("ueUsageType", field->name) && row[i] != NULL) {
        std::string s = row[i];
        std::stringstream ss;
        int32_t a;
        ss << s;
        ss >> a;
        accessandmobilitysubscriptiondata.setUeUsageType(a);
      } else if (!strcmp("mpsPriority", field->name) && row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setMpsPriority(true);
        else
          accessandmobilitysubscriptiondata.setMpsPriority(false);
      } else if (!strcmp("mcsPriority", field->name) && row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setMcsPriority(true);
        else
          accessandmobilitysubscriptiondata.setMcsPriority(false);
      } else if (!strcmp("activeTime", field->name) && row[i] != NULL) {
        std::string s = row[i];
        std::stringstream ss;
        int32_t a;
        ss << s;
        ss >> a;
        accessandmobilitysubscriptiondata.setActiveTime(a);
      } else if (!strcmp("sorInfo", field->name) && row[i] != NULL) {
        SorInfo sorinfo;
        nlohmann::json::parse(row[i]).get_to(sorinfo);
        accessandmobilitysubscriptiondata.setSorInfo(sorinfo);
      } else if (!strcmp("sorInfoExpectInd", field->name) && row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setSorInfoExpectInd(true);
        else
          accessandmobilitysubscriptiondata.setSorInfoExpectInd(false);
      } else if (!strcmp("sorafRetrieval", field->name) && row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setSorafRetrieval(true);
        else
          accessandmobilitysubscriptiondata.setSorafRetrieval(false);
      } else if (!strcmp("sorUpdateIndicatorList", field->name) &&
                 row[i] != NULL) {
        std ::vector<SorUpdateIndicator> sorupdateindicatorlist;
        nlohmann::json::parse(row[i]).get_to(sorupdateindicatorlist);
        accessandmobilitysubscriptiondata.setSorUpdateIndicatorList(
            sorupdateindicatorlist);
      } else if (!strcmp("upuInfo", field->name) && row[i] != NULL) {
        UpuInfo upuinfo;
        nlohmann::json::parse(row[i]).get_to(upuinfo);
        accessandmobilitysubscriptiondata.setUpuInfo(upuinfo);
      } else if (!strcmp("micoAllowed", field->name) && row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setMicoAllowed(true);
        else
          accessandmobilitysubscriptiondata.setMicoAllowed(false);
      } else if (!strcmp("sharedAmDataIds", field->name) && row[i] != NULL) {
        std ::vector<std ::string> sharedamdataids;
        nlohmann::json::parse(row[i]).get_to(sharedamdataids);
        accessandmobilitysubscriptiondata.setSharedAmDataIds(sharedamdataids);
      } else if (!strcmp("odbPacketServices", field->name) && row[i] != NULL) {
        OdbPacketServices odbpacketservices;
        nlohmann::json::parse(row[i]).get_to(odbpacketservices);
        accessandmobilitysubscriptiondata.setOdbPacketServices(
            odbpacketservices);
      } else if (!strcmp("serviceGapTime", field->name) && row[i] != NULL) {
        std::string s = row[i];
        std::stringstream ss;
        int32_t a;
        ss << s;
        ss >> a;
        accessandmobilitysubscriptiondata.setServiceGapTime(a);
      } else if (!strcmp("mdtUserConsent", field->name) && row[i] != NULL) {
        MdtUserConsent mdtuserconsent;
        nlohmann::json::parse(row[i]).get_to(mdtuserconsent);
        accessandmobilitysubscriptiondata.setMdtUserConsent(mdtuserconsent);
      } else if (!strcmp("mdtConfiguration", field->name) && row[i] != NULL) {
        MdtConfiguration mdtconfiguration;
        nlohmann::json::parse(row[i]).get_to(mdtconfiguration);
        accessandmobilitysubscriptiondata.setMdtConfiguration(mdtconfiguration);
      } else if (!strcmp("traceData", field->name) && row[i] != NULL) {
        TraceData tracedata;
        nlohmann::json::parse(row[i]).get_to(tracedata);
        accessandmobilitysubscriptiondata.setTraceData(tracedata);
      } else if (!strcmp("cagData", field->name) && row[i] != NULL) {
        CagData cagdata;
        nlohmann::json::parse(row[i]).get_to(cagdata);
        accessandmobilitysubscriptiondata.setCagData(cagdata);
      } else if (!strcmp("stnSr", field->name) && row[i] != NULL) {
        accessandmobilitysubscriptiondata.setStnSr(row[i]);
      } else if (!strcmp("cMsisdn", field->name) && row[i] != NULL) {
        accessandmobilitysubscriptiondata.setCMsisdn(row[i]);
      } else if (!strcmp("nbIoTUePriority", field->name) && row[i] != NULL) {
        std::string s = row[i];
        std::stringstream ss;
        int32_t a;
        ss << s;
        ss >> a;
        accessandmobilitysubscriptiondata.setNbIoTUePriority(a);
      } else if (!strcmp("nssaiInclusionAllowed", field->name) &&
                 row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setNssaiInclusionAllowed(true);
        else
          accessandmobilitysubscriptiondata.setNssaiInclusionAllowed(false);
      } else if (!strcmp("rgWirelineCharacteristics", field->name) &&
                 row[i] != NULL) {
        accessandmobilitysubscriptiondata.setRgWirelineCharacteristics(row[i]);
      } else if (!strcmp("ecRestrictionDataWb", field->name) &&
                 row[i] != NULL) {
        EcRestrictionDataWb ecrestrictiondatawb;
        nlohmann::json::parse(row[i]).get_to(ecrestrictiondatawb);
        accessandmobilitysubscriptiondata.setEcRestrictionDataWb(
            ecrestrictiondatawb);
      } else if (!strcmp("ecRestrictionDataNb", field->name) &&
                 row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setEcRestrictionDataNb(true);
        else
          accessandmobilitysubscriptiondata.setEcRestrictionDataNb(false);
      } else if (!strcmp("expectedUeBehaviourList", field->name) &&
                 row[i] != NULL) {
        ExpectedUeBehaviourData expecteduebehaviourlist;
        nlohmann::json::parse(row[i]).get_to(expecteduebehaviourlist);
        accessandmobilitysubscriptiondata.setExpectedUeBehaviourList(
            expecteduebehaviourlist);
      } else if (!strcmp("primaryRatRestrictions", field->name) &&
                 row[i] != NULL) {
        std ::vector<RatType> primaryratrestrictions;
        nlohmann::json::parse(row[i]).get_to(primaryratrestrictions);
        accessandmobilitysubscriptiondata.setPrimaryRatRestrictions(
            primaryratrestrictions);
      } else if (!strcmp("secondaryRatRestrictions", field->name) &&
                 row[i] != NULL) {
        std ::vector<RatType> secondaryratrestrictions;
        nlohmann::json::parse(row[i]).get_to(secondaryratrestrictions);
        accessandmobilitysubscriptiondata.setSecondaryRatRestrictions(
            secondaryratrestrictions);
      } else if (!strcmp("edrxParametersList", field->name) && row[i] != NULL) {
        std ::vector<EdrxParameters> edrxparameterslist;
        nlohmann::json::parse(row[i]).get_to(edrxparameterslist);
        accessandmobilitysubscriptiondata.setEdrxParametersList(
            edrxparameterslist);
      } else if (!strcmp("ptwParametersList", field->name) && row[i] != NULL) {
        std ::vector<PtwParameters> ptwparameterslist;
        nlohmann::json::parse(row[i]).get_to(ptwparameterslist);
        accessandmobilitysubscriptiondata.setPtwParametersList(
            ptwparameterslist);
      } else if (!strcmp("iabOperationAllowed", field->name) &&
                 row[i] != NULL) {
        if (strcmp(row[i], "0"))
          accessandmobilitysubscriptiondata.setIabOperationAllowed(true);
        else
          accessandmobilitysubscriptiondata.setIabOperationAllowed(false);
      } else if (!strcmp("wirelineForbiddenAreas", field->name) &&
                 row[i] != NULL) {
        std ::vector<WirelineArea> wirelineforbiddenareas;
        nlohmann::json::parse(row[i]).get_to(wirelineforbiddenareas);
        accessandmobilitysubscriptiondata.setWirelineForbiddenAreas(
            wirelineforbiddenareas);
      } else if (!strcmp("wirelineServiceAreaRestriction", field->name) &&
                 row[i] != NULL) {
        WirelineServiceAreaRestriction wirelineservicearearestriction;
        nlohmann::json::parse(row[i]).get_to(wirelineservicearearestriction);
        accessandmobilitysubscriptiondata.setWirelineServiceAreaRestriction(
            wirelineservicearearestriction);
      }
    }

    to_json(j, accessandmobilitysubscriptiondata);
    response.send(Pistache::Http::Code::Ok, j.dump());
  } else {
    std::cout << "AuthenticationSubscription no data！" << std::endl;
  }

  mysql_free_result(res);
}

} // namespace api
} // namespace server
} // namespace openapitools
} // namespace org
