text: ﻿/*
  * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License").
  * You may not use this file except in compliance with the License.
  * A copy of the License is located at
  *
  *  http://aws.amazon.com/apache2.0
  *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
  
  #include <aws/ec2/model/TransitGatewayVpcAttachment.h>
  #include <aws/core/utils/xml/XmlSerializer.h>
  #include <aws/core/utils/StringUtils.h>
  #include <aws/core/utils/memory/stl/AWSStringStream.h>
  
  #include <utility>
  
  using namespace Aws::Utils::Xml;
  using namespace Aws::Utils;
  
  namespace Aws
  {
  namespace EC2
  {
  namespace Model
  {
  
  TransitGatewayVpcAttachment::TransitGatewayVpcAttachment() : 
      m_transitGatewayAttachmentIdHasBeenSet(false),
      m_transitGatewayIdHasBeenSet(false),
      m_vpcIdHasBeenSet(false),
      m_vpcOwnerIdHasBeenSet(false),
      m_state(TransitGatewayAttachmentState::NOT_SET),
      m_stateHasBeenSet(false),
      m_subnetIdsHasBeenSet(false),
      m_creationTimeHasBeenSet(false),
      m_optionsHasBeenSet(false),
      m_tagsHasBeenSet(false)
  {
  }
  
  TransitGatewayVpcAttachment::TransitGatewayVpcAttachment(const XmlNode& xmlNode) : 
      m_transitGatewayAttachmentIdHasBeenSet(false),
      m_transitGatewayIdHasBeenSet(false),
      m_vpcIdHasBeenSet(false),
      m_vpcOwnerIdHasBeenSet(false),
      m_state(TransitGatewayAttachmentState::NOT_SET),
      m_stateHasBeenSet(false),
      m_subnetIdsHasBeenSet(false),
      m_creationTimeHasBeenSet(false),
      m_optionsHasBeenSet(false),
      m_tagsHasBeenSet(false)
  {
    *this = xmlNode;
  }
  
  TransitGatewayVpcAttachment& TransitGatewayVpcAttachment::operator =(const XmlNode& xmlNode)
  {
    XmlNode resultNode = xmlNode;
  
    if(!resultNode.IsNull())
    {
      XmlNode transitGatewayAttachmentIdNode = resultNode.FirstChild("transitGatewayAttachmentId");
      if(!transitGatewayAttachmentIdNode.IsNull())
      {
        m_transitGatewayAttachmentId = StringUtils::Trim(transitGatewayAttachmentIdNode.GetText().c_str());
        m_transitGatewayAttachmentIdHasBeenSet = true;
      }
      XmlNode transitGatewayIdNode = resultNode.FirstChild("transitGatewayId");
      if(!transitGatewayIdNode.IsNull())
      {
        m_transitGatewayId = StringUtils::Trim(transitGatewayIdNode.GetText().c_str());
        m_transitGatewayIdHasBeenSet = true;
      }
      XmlNode vpcIdNode = resultNode.FirstChild("vpcId");
      if(!vpcIdNode.IsNull())
      {
        m_vpcId = StringUtils::Trim(vpcIdNode.GetText().c_str());
        m_vpcIdHasBeenSet = true;
      }
      XmlNode vpcOwnerIdNode = resultNode.FirstChild("vpcOwnerId");
      if(!vpcOwnerIdNode.IsNull())
      {
        m_vpcOwnerId = StringUtils::Trim(vpcOwnerIdNode.GetText().c_str());
        m_vpcOwnerIdHasBeenSet = true;
      }
      XmlNode stateNode = resultNode.FirstChild("state");
      if(!stateNode.IsNull())
      {
        m_state = TransitGatewayAttachmentStateMapper::GetTransitGatewayAttachmentStateForName(StringUtils::Trim(stateNode.GetText().c_str()).c_str());
        m_stateHasBeenSet = true;
      }
      XmlNode subnetIdsNode = resultNode.FirstChild("subnetIds");
      if(!subnetIdsNode.IsNull())
      {
        XmlNode subnetIdsMember = subnetIdsNode.FirstChild("item");
        while(!subnetIdsMember.IsNull())
        {
          m_subnetIds.push_back(StringUtils::Trim(subnetIdsMember.GetText().c_str()));
          subnetIdsMember = subnetIdsMember.NextNode("item");
        }
  
        m_subnetIdsHasBeenSet = true;
      }
      XmlNode creationTimeNode = resultNode.FirstChild("creationTime");
      if(!creationTimeNode.IsNull())
      {
        m_creationTime = DateTime(StringUtils::Trim(creationTimeNode.GetText().c_str()).c_str(), DateFormat::ISO_8601);
        m_creationTimeHasBeenSet = true;
      }
      XmlNode optionsNode = resultNode.FirstChild("options");
      if(!optionsNode.IsNull())
      {
        m_options = optionsNode;
        m_optionsHasBeenSet = true;
      }
      XmlNode tagsNode = resultNode.FirstChild("tagSet");
      if(!tagsNode.IsNull())
      {
        XmlNode tagsMember = tagsNode.FirstChild("item");
        while(!tagsMember.IsNull())
        {
          m_tags.push_back(tagsMember);
          tagsMember = tagsMember.NextNode("item");
        }
  
        m_tagsHasBeenSet = true;
      }
    }
  
    return *this;
  }
  
  void TransitGatewayVpcAttachment::OutputToStream(Aws::OStream& oStream, const char* location, unsigned index, const char* locationValue) const
  {
    if(m_transitGatewayAttachmentIdHasBeenSet)
    {
        oStream << location << index << locationValue << ".TransitGatewayAttachmentId=" << StringUtils::URLEncode(m_transitGatewayAttachmentId.c_str()) << "&";
    }
  
    if(m_transitGatewayIdHasBeenSet)
    {
        oStream << location << index << locationValue << ".TransitGatewayId=" << StringUtils::URLEncode(m_transitGatewayId.c_str()) << "&";
    }
  
    if(m_vpcIdHasBeenSet)
    {
        oStream << location << index << locationValue << ".VpcId=" << StringUtils::URLEncode(m_vpcId.c_str()) << "&";
    }
  
    if(m_vpcOwnerIdHasBeenSet)
    {
        oStream << location << index << locationValue << ".VpcOwnerId=" << StringUtils::URLEncode(m_vpcOwnerId.c_str()) << "&";
    }
  
    if(m_stateHasBeenSet)
    {
        oStream << location << index << locationValue << ".State=" << TransitGatewayAttachmentStateMapper::GetNameForTransitGatewayAttachmentState(m_state) << "&";
    }
  
    if(m_subnetIdsHasBeenSet)
    {
        unsigned subnetIdsIdx = 1;
        for(auto& item : m_subnetIds)
        {
          oStream << location << index << locationValue << ".SubnetIds." << subnetIdsIdx++ << "=" << StringUtils::URLEncode(item.c_str()) << "&";
        }
    }
  
    if(m_creationTimeHasBeenSet)
    {
        oStream << location << index << locationValue << ".CreationTime=" << StringUtils::URLEncode(m_creationTime.ToGmtString(DateFormat::ISO_8601).c_str()) << "&";
    }
  
    if(m_optionsHasBeenSet)
    {
        Aws::StringStream optionsLocationAndMemberSs;
        optionsLocationAndMemberSs << location << index << locationValue << ".Options";
        m_options.OutputToStream(oStream, optionsLocationAndMemberSs.str().c_str());
    }
  
    if(m_tagsHasBeenSet)
    {
        unsigned tagsIdx = 1;
        for(auto& item : m_tags)
        {
          Aws::StringStream tagsSs;
          tagsSs << location << index << locationValue << ".TagSet." << tagsIdx++;
          item.OutputToStream(oStream, tagsSs.str().c_str());
        }
    }
  
  }
  
  void TransitGatewayVpcAttachment::OutputToStream(Aws::OStream& oStream, const char* location) const
  {
    if(m_transitGatewayAttachmentIdHasBeenSet)
    {
        oStream << location << ".TransitGatewayAttachmentId=" << StringUtils::URLEncode(m_transitGatewayAttachmentId.c_str()) << "&";
    }
    if(m_transitGatewayIdHasBeenSet)
    {
        oStream << location << ".TransitGatewayId=" << StringUtils::URLEncode(m_transitGatewayId.c_str()) << "&";
    }
    if(m_vpcIdHasBeenSet)
    {
        oStream << location << ".VpcId=" << StringUtils::URLEncode(m_vpcId.c_str()) << "&";
    }
    if(m_vpcOwnerIdHasBeenSet)
    {
        oStream << location << ".VpcOwnerId=" << StringUtils::URLEncode(m_vpcOwnerId.c_str()) << "&";
    }
    if(m_stateHasBeenSet)
    {
        oStream << location << ".State=" << TransitGatewayAttachmentStateMapper::GetNameForTransitGatewayAttachmentState(m_state) << "&";
    }
    if(m_subnetIdsHasBeenSet)
    {
        unsigned subnetIdsIdx = 1;
        for(auto& item : m_subnetIds)
        {
          oStream << location << ".SubnetIds." << subnetIdsIdx++ << "=" << StringUtils::URLEncode(item.c_str()) << "&";
        }
    }
    if(m_creationTimeHasBeenSet)
    {
        oStream << location << ".CreationTime=" << StringUtils::URLEncode(m_creationTime.ToGmtString(DateFormat::ISO_8601).c_str()) << "&";
    }
    if(m_optionsHasBeenSet)
    {
        Aws::String optionsLocationAndMember(location);
        optionsLocationAndMember += ".Options";
        m_options.OutputToStream(oStream, optionsLocationAndMember.c_str());
    }
    if(m_tagsHasBeenSet)
    {
        unsigned tagsIdx = 1;
        for(auto& item : m_tags)
        {
          Aws::StringStream tagsSs;
          tagsSs << location <<  ".TagSet." << tagsIdx++;
          item.OutputToStream(oStream, tagsSs.str().c_str());
        }
    }
  }
  
  } // namespace Model
  } // namespace EC2
  } // namespace Aws
  