/**
 * Nsmf_PDUSession
 * SMF PDU Session 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 4.1.1-SNAPSHOT.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

#include "ReleaseData.h"

namespace oai {
namespace smf {
namespace model {

ReleaseData::ReleaseData() {
  m_CauseIsSet                   = false;
  m_NgApCauseIsSet               = false;
  m__5gMmCauseValue              = 0;
  m__5gMmCauseValueIsSet         = false;
  m_UeLocationIsSet              = false;
  m_UeTimeZone                   = utility::conversions::to_string_t("");
  m_UeTimeZoneIsSet              = false;
  m_AddUeLocationIsSet           = false;
  m_SecondaryRatUsageReportIsSet = false;
  m_SecondaryRatUsageInfoIsSet   = false;
}

ReleaseData::~ReleaseData() {}

void ReleaseData::validate() {
  // TODO: implement validation
}

web::json::value ReleaseData::toJson() const {
  web::json::value val = web::json::value::object();

  if (m_CauseIsSet) {
    val[utility::conversions::to_string_t("cause")] =
        ModelBase::toJson(m_Cause);
  }
  if (m_NgApCauseIsSet) {
    val[utility::conversions::to_string_t("ngApCause")] =
        ModelBase::toJson(m_NgApCause);
  }
  if (m__5gMmCauseValueIsSet) {
    val[utility::conversions::to_string_t("5gMmCauseValue")] =
        ModelBase::toJson(m__5gMmCauseValue);
  }
  if (m_UeLocationIsSet) {
    val[utility::conversions::to_string_t("ueLocation")] =
        ModelBase::toJson(m_UeLocation);
  }
  if (m_UeTimeZoneIsSet) {
    val[utility::conversions::to_string_t("ueTimeZone")] =
        ModelBase::toJson(m_UeTimeZone);
  }
  if (m_AddUeLocationIsSet) {
    val[utility::conversions::to_string_t("addUeLocation")] =
        ModelBase::toJson(m_AddUeLocation);
  }
  {
    std::vector<web::json::value> jsonArray;
    for (auto& item : m_SecondaryRatUsageReport) {
      jsonArray.push_back(ModelBase::toJson(item));
    }
    if (jsonArray.size() > 0) {
      val[utility::conversions::to_string_t("secondaryRatUsageReport")] =
          web::json::value::array(jsonArray);
    }
  }
  {
    std::vector<web::json::value> jsonArray;
    for (auto& item : m_SecondaryRatUsageInfo) {
      jsonArray.push_back(ModelBase::toJson(item));
    }
    if (jsonArray.size() > 0) {
      val[utility::conversions::to_string_t("secondaryRatUsageInfo")] =
          web::json::value::array(jsonArray);
    }
  }

  return val;
}

void ReleaseData::fromJson(const web::json::value& val) {
  if (val.has_field(utility::conversions::to_string_t("cause"))) {
    const web::json::value& fieldValue =
        val.at(utility::conversions::to_string_t("cause"));
    if (!fieldValue.is_null()) {
      std::shared_ptr<Cause> newItem(new Cause());
      newItem->fromJson(fieldValue);
      setCause(newItem);
    }
  }
  if (val.has_field(utility::conversions::to_string_t("ngApCause"))) {
    const web::json::value& fieldValue =
        val.at(utility::conversions::to_string_t("ngApCause"));
    if (!fieldValue.is_null()) {
      std::shared_ptr<NgApCause> newItem(new NgApCause());
      newItem->fromJson(fieldValue);
      setNgApCause(newItem);
    }
  }
  if (val.has_field(utility::conversions::to_string_t("5gMmCauseValue"))) {
    const web::json::value& fieldValue =
        val.at(utility::conversions::to_string_t("5gMmCauseValue"));
    if (!fieldValue.is_null()) {
      set5gMmCauseValue(ModelBase::int32_tFromJson(fieldValue));
    }
  }
  if (val.has_field(utility::conversions::to_string_t("ueLocation"))) {
    const web::json::value& fieldValue =
        val.at(utility::conversions::to_string_t("ueLocation"));
    if (!fieldValue.is_null()) {
      std::shared_ptr<UserLocation> newItem(new UserLocation());
      newItem->fromJson(fieldValue);
      setUeLocation(newItem);
    }
  }
  if (val.has_field(utility::conversions::to_string_t("ueTimeZone"))) {
    const web::json::value& fieldValue =
        val.at(utility::conversions::to_string_t("ueTimeZone"));
    if (!fieldValue.is_null()) {
      setUeTimeZone(ModelBase::stringFromJson(fieldValue));
    }
  }
  if (val.has_field(utility::conversions::to_string_t("addUeLocation"))) {
    const web::json::value& fieldValue =
        val.at(utility::conversions::to_string_t("addUeLocation"));
    if (!fieldValue.is_null()) {
      std::shared_ptr<UserLocation> newItem(new UserLocation());
      newItem->fromJson(fieldValue);
      setAddUeLocation(newItem);
    }
  }
  {
    m_SecondaryRatUsageReport.clear();
    std::vector<web::json::value> jsonArray;
    if (val.has_field(
            utility::conversions::to_string_t("secondaryRatUsageReport"))) {
      for (auto& item :
           val.at(utility::conversions::to_string_t("secondaryRatUsageReport"))
               .as_array()) {
        if (item.is_null()) {
          m_SecondaryRatUsageReport.push_back(
              std::shared_ptr<SecondaryRatUsageReport>(nullptr));
        } else {
          std::shared_ptr<SecondaryRatUsageReport> newItem(
              new SecondaryRatUsageReport());
          newItem->fromJson(item);
          m_SecondaryRatUsageReport.push_back(newItem);
        }
      }
    }
  }
  {
    m_SecondaryRatUsageInfo.clear();
    std::vector<web::json::value> jsonArray;
    if (val.has_field(
            utility::conversions::to_string_t("secondaryRatUsageInfo"))) {
      for (auto& item :
           val.at(utility::conversions::to_string_t("secondaryRatUsageInfo"))
               .as_array()) {
        if (item.is_null()) {
          m_SecondaryRatUsageInfo.push_back(
              std::shared_ptr<SecondaryRatUsageInfo>(nullptr));
        } else {
          std::shared_ptr<SecondaryRatUsageInfo> newItem(
              new SecondaryRatUsageInfo());
          newItem->fromJson(item);
          m_SecondaryRatUsageInfo.push_back(newItem);
        }
      }
    }
  }
}

void ReleaseData::toMultipart(
    std::shared_ptr<MultipartFormData> multipart,
    const utility::string_t& prefix) const {
  utility::string_t namePrefix = prefix;
  if (namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) !=
                                   utility::conversions::to_string_t(".")) {
    namePrefix += utility::conversions::to_string_t(".");
  }

  if (m_CauseIsSet) {
    if (m_Cause.get()) {
      m_Cause->toMultipart(
          multipart, utility::conversions::to_string_t("cause."));
    }
  }
  if (m_NgApCauseIsSet) {
    if (m_NgApCause.get()) {
      m_NgApCause->toMultipart(
          multipart, utility::conversions::to_string_t("ngApCause."));
    }
  }
  if (m__5gMmCauseValueIsSet) {
    multipart->add(ModelBase::toHttpContent(
        namePrefix + utility::conversions::to_string_t("5gMmCauseValue"),
        m__5gMmCauseValue));
  }
  if (m_UeLocationIsSet) {
    if (m_UeLocation.get()) {
      m_UeLocation->toMultipart(
          multipart, utility::conversions::to_string_t("ueLocation."));
    }
  }
  if (m_UeTimeZoneIsSet) {
    multipart->add(ModelBase::toHttpContent(
        namePrefix + utility::conversions::to_string_t("ueTimeZone"),
        m_UeTimeZone));
  }
  if (m_AddUeLocationIsSet) {
    if (m_AddUeLocation.get()) {
      m_AddUeLocation->toMultipart(
          multipart, utility::conversions::to_string_t("addUeLocation."));
    }
  }
  {
    std::vector<web::json::value> jsonArray;
    for (auto& item : m_SecondaryRatUsageReport) {
      jsonArray.push_back(ModelBase::toJson(item));
    }

    if (jsonArray.size() > 0) {
      multipart->add(ModelBase::toHttpContent(
          namePrefix +
              utility::conversions::to_string_t("secondaryRatUsageReport"),
          web::json::value::array(jsonArray),
          utility::conversions::to_string_t("application/json")));
    }
  }
  {
    std::vector<web::json::value> jsonArray;
    for (auto& item : m_SecondaryRatUsageInfo) {
      jsonArray.push_back(ModelBase::toJson(item));
    }

    if (jsonArray.size() > 0) {
      multipart->add(ModelBase::toHttpContent(
          namePrefix +
              utility::conversions::to_string_t("secondaryRatUsageInfo"),
          web::json::value::array(jsonArray),
          utility::conversions::to_string_t("application/json")));
    }
  }
}

void ReleaseData::fromMultiPart(
    std::shared_ptr<MultipartFormData> multipart,
    const utility::string_t& prefix) {
  utility::string_t namePrefix = prefix;
  if (namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) !=
                                   utility::conversions::to_string_t(".")) {
    namePrefix += utility::conversions::to_string_t(".");
  }

  if (multipart->hasContent(utility::conversions::to_string_t("cause"))) {
    if (multipart->hasContent(utility::conversions::to_string_t("cause"))) {
      std::shared_ptr<Cause> newItem(new Cause());
      newItem->fromMultiPart(
          multipart, utility::conversions::to_string_t("cause."));
      setCause(newItem);
    }
  }
  if (multipart->hasContent(utility::conversions::to_string_t("ngApCause"))) {
    if (multipart->hasContent(utility::conversions::to_string_t("ngApCause"))) {
      std::shared_ptr<NgApCause> newItem(new NgApCause());
      newItem->fromMultiPart(
          multipart, utility::conversions::to_string_t("ngApCause."));
      setNgApCause(newItem);
    }
  }
  if (multipart->hasContent(
          utility::conversions::to_string_t("5gMmCauseValue"))) {
    set5gMmCauseValue(ModelBase::int32_tFromHttpContent(multipart->getContent(
        utility::conversions::to_string_t("5gMmCauseValue"))));
  }
  if (multipart->hasContent(utility::conversions::to_string_t("ueLocation"))) {
    if (multipart->hasContent(
            utility::conversions::to_string_t("ueLocation"))) {
      std::shared_ptr<UserLocation> newItem(new UserLocation());
      newItem->fromMultiPart(
          multipart, utility::conversions::to_string_t("ueLocation."));
      setUeLocation(newItem);
    }
  }
  if (multipart->hasContent(utility::conversions::to_string_t("ueTimeZone"))) {
    setUeTimeZone(ModelBase::stringFromHttpContent(multipart->getContent(
        utility::conversions::to_string_t("ueTimeZone"))));
  }
  if (multipart->hasContent(
          utility::conversions::to_string_t("addUeLocation"))) {
    if (multipart->hasContent(
            utility::conversions::to_string_t("addUeLocation"))) {
      std::shared_ptr<UserLocation> newItem(new UserLocation());
      newItem->fromMultiPart(
          multipart, utility::conversions::to_string_t("addUeLocation."));
      setAddUeLocation(newItem);
    }
  }
  {
    m_SecondaryRatUsageReport.clear();
    if (multipart->hasContent(
            utility::conversions::to_string_t("secondaryRatUsageReport"))) {
      web::json::value jsonArray = web::json::value::parse(
          ModelBase::stringFromHttpContent(multipart->getContent(
              utility::conversions::to_string_t("secondaryRatUsageReport"))));
      for (auto& item : jsonArray.as_array()) {
        if (item.is_null()) {
          m_SecondaryRatUsageReport.push_back(
              std::shared_ptr<SecondaryRatUsageReport>(nullptr));
        } else {
          std::shared_ptr<SecondaryRatUsageReport> newItem(
              new SecondaryRatUsageReport());
          newItem->fromJson(item);
          m_SecondaryRatUsageReport.push_back(newItem);
        }
      }
    }
  }
  {
    m_SecondaryRatUsageInfo.clear();
    if (multipart->hasContent(
            utility::conversions::to_string_t("secondaryRatUsageInfo"))) {
      web::json::value jsonArray = web::json::value::parse(
          ModelBase::stringFromHttpContent(multipart->getContent(
              utility::conversions::to_string_t("secondaryRatUsageInfo"))));
      for (auto& item : jsonArray.as_array()) {
        if (item.is_null()) {
          m_SecondaryRatUsageInfo.push_back(
              std::shared_ptr<SecondaryRatUsageInfo>(nullptr));
        } else {
          std::shared_ptr<SecondaryRatUsageInfo> newItem(
              new SecondaryRatUsageInfo());
          newItem->fromJson(item);
          m_SecondaryRatUsageInfo.push_back(newItem);
        }
      }
    }
  }
}

std::shared_ptr<Cause> ReleaseData::getCause() const {
  return m_Cause;
}

void ReleaseData::setCause(const std::shared_ptr<Cause>& value) {
  m_Cause      = value;
  m_CauseIsSet = true;
}

bool ReleaseData::causeIsSet() const {
  return m_CauseIsSet;
}

void ReleaseData::unsetCause() {
  m_CauseIsSet = false;
}

std::shared_ptr<NgApCause> ReleaseData::getNgApCause() const {
  return m_NgApCause;
}

void ReleaseData::setNgApCause(const std::shared_ptr<NgApCause>& value) {
  m_NgApCause      = value;
  m_NgApCauseIsSet = true;
}

bool ReleaseData::ngApCauseIsSet() const {
  return m_NgApCauseIsSet;
}

void ReleaseData::unsetNgApCause() {
  m_NgApCauseIsSet = false;
}

int32_t ReleaseData::get5gMmCauseValue() const {
  return m__5gMmCauseValue;
}

void ReleaseData::set5gMmCauseValue(int32_t value) {
  m__5gMmCauseValue      = value;
  m__5gMmCauseValueIsSet = true;
}

bool ReleaseData::_5gMmCauseValueIsSet() const {
  return m__5gMmCauseValueIsSet;
}

void ReleaseData::unset_5gMmCauseValue() {
  m__5gMmCauseValueIsSet = false;
}

std::shared_ptr<UserLocation> ReleaseData::getUeLocation() const {
  return m_UeLocation;
}

void ReleaseData::setUeLocation(const std::shared_ptr<UserLocation>& value) {
  m_UeLocation      = value;
  m_UeLocationIsSet = true;
}

bool ReleaseData::ueLocationIsSet() const {
  return m_UeLocationIsSet;
}

void ReleaseData::unsetUeLocation() {
  m_UeLocationIsSet = false;
}

utility::string_t ReleaseData::getUeTimeZone() const {
  return m_UeTimeZone;
}

void ReleaseData::setUeTimeZone(const utility::string_t& value) {
  m_UeTimeZone      = value;
  m_UeTimeZoneIsSet = true;
}

bool ReleaseData::ueTimeZoneIsSet() const {
  return m_UeTimeZoneIsSet;
}

void ReleaseData::unsetUeTimeZone() {
  m_UeTimeZoneIsSet = false;
}

std::shared_ptr<UserLocation> ReleaseData::getAddUeLocation() const {
  return m_AddUeLocation;
}

void ReleaseData::setAddUeLocation(const std::shared_ptr<UserLocation>& value) {
  m_AddUeLocation      = value;
  m_AddUeLocationIsSet = true;
}

bool ReleaseData::addUeLocationIsSet() const {
  return m_AddUeLocationIsSet;
}

void ReleaseData::unsetAddUeLocation() {
  m_AddUeLocationIsSet = false;
}

std::vector<std::shared_ptr<SecondaryRatUsageReport>>&
ReleaseData::getSecondaryRatUsageReport() {
  return m_SecondaryRatUsageReport;
}

void ReleaseData::setSecondaryRatUsageReport(
    const std::vector<std::shared_ptr<SecondaryRatUsageReport>>& value) {
  m_SecondaryRatUsageReport      = value;
  m_SecondaryRatUsageReportIsSet = true;
}

bool ReleaseData::secondaryRatUsageReportIsSet() const {
  return m_SecondaryRatUsageReportIsSet;
}

void ReleaseData::unsetSecondaryRatUsageReport() {
  m_SecondaryRatUsageReportIsSet = false;
}

std::vector<std::shared_ptr<SecondaryRatUsageInfo>>&
ReleaseData::getSecondaryRatUsageInfo() {
  return m_SecondaryRatUsageInfo;
}

void ReleaseData::setSecondaryRatUsageInfo(
    const std::vector<std::shared_ptr<SecondaryRatUsageInfo>>& value) {
  m_SecondaryRatUsageInfo      = value;
  m_SecondaryRatUsageInfoIsSet = true;
}

bool ReleaseData::secondaryRatUsageInfoIsSet() const {
  return m_SecondaryRatUsageInfoIsSet;
}

void ReleaseData::unsetSecondaryRatUsageInfo() {
  m_SecondaryRatUsageInfoIsSet = false;
}

}  // namespace model
}  // namespace smf
}  // namespace oai
