1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/lightsail/model/Instance.h>
7 #include <aws/core/utils/json/JsonSerializer.h>
8 
9 #include <utility>
10 
11 using namespace Aws::Utils::Json;
12 using namespace Aws::Utils;
13 
14 namespace Aws
15 {
16 namespace Lightsail
17 {
18 namespace Model
19 {
20 
Instance()21 Instance::Instance() :
22     m_nameHasBeenSet(false),
23     m_arnHasBeenSet(false),
24     m_supportCodeHasBeenSet(false),
25     m_createdAtHasBeenSet(false),
26     m_locationHasBeenSet(false),
27     m_resourceType(ResourceType::NOT_SET),
28     m_resourceTypeHasBeenSet(false),
29     m_tagsHasBeenSet(false),
30     m_blueprintIdHasBeenSet(false),
31     m_blueprintNameHasBeenSet(false),
32     m_bundleIdHasBeenSet(false),
33     m_addOnsHasBeenSet(false),
34     m_isStaticIp(false),
35     m_isStaticIpHasBeenSet(false),
36     m_privateIpAddressHasBeenSet(false),
37     m_publicIpAddressHasBeenSet(false),
38     m_ipv6AddressesHasBeenSet(false),
39     m_ipAddressType(IpAddressType::NOT_SET),
40     m_ipAddressTypeHasBeenSet(false),
41     m_hardwareHasBeenSet(false),
42     m_networkingHasBeenSet(false),
43     m_stateHasBeenSet(false),
44     m_usernameHasBeenSet(false),
45     m_sshKeyNameHasBeenSet(false)
46 {
47 }
48 
Instance(JsonView jsonValue)49 Instance::Instance(JsonView jsonValue) :
50     m_nameHasBeenSet(false),
51     m_arnHasBeenSet(false),
52     m_supportCodeHasBeenSet(false),
53     m_createdAtHasBeenSet(false),
54     m_locationHasBeenSet(false),
55     m_resourceType(ResourceType::NOT_SET),
56     m_resourceTypeHasBeenSet(false),
57     m_tagsHasBeenSet(false),
58     m_blueprintIdHasBeenSet(false),
59     m_blueprintNameHasBeenSet(false),
60     m_bundleIdHasBeenSet(false),
61     m_addOnsHasBeenSet(false),
62     m_isStaticIp(false),
63     m_isStaticIpHasBeenSet(false),
64     m_privateIpAddressHasBeenSet(false),
65     m_publicIpAddressHasBeenSet(false),
66     m_ipv6AddressesHasBeenSet(false),
67     m_ipAddressType(IpAddressType::NOT_SET),
68     m_ipAddressTypeHasBeenSet(false),
69     m_hardwareHasBeenSet(false),
70     m_networkingHasBeenSet(false),
71     m_stateHasBeenSet(false),
72     m_usernameHasBeenSet(false),
73     m_sshKeyNameHasBeenSet(false)
74 {
75   *this = jsonValue;
76 }
77 
operator =(JsonView jsonValue)78 Instance& Instance::operator =(JsonView jsonValue)
79 {
80   if(jsonValue.ValueExists("name"))
81   {
82     m_name = jsonValue.GetString("name");
83 
84     m_nameHasBeenSet = true;
85   }
86 
87   if(jsonValue.ValueExists("arn"))
88   {
89     m_arn = jsonValue.GetString("arn");
90 
91     m_arnHasBeenSet = true;
92   }
93 
94   if(jsonValue.ValueExists("supportCode"))
95   {
96     m_supportCode = jsonValue.GetString("supportCode");
97 
98     m_supportCodeHasBeenSet = true;
99   }
100 
101   if(jsonValue.ValueExists("createdAt"))
102   {
103     m_createdAt = jsonValue.GetDouble("createdAt");
104 
105     m_createdAtHasBeenSet = true;
106   }
107 
108   if(jsonValue.ValueExists("location"))
109   {
110     m_location = jsonValue.GetObject("location");
111 
112     m_locationHasBeenSet = true;
113   }
114 
115   if(jsonValue.ValueExists("resourceType"))
116   {
117     m_resourceType = ResourceTypeMapper::GetResourceTypeForName(jsonValue.GetString("resourceType"));
118 
119     m_resourceTypeHasBeenSet = true;
120   }
121 
122   if(jsonValue.ValueExists("tags"))
123   {
124     Array<JsonView> tagsJsonList = jsonValue.GetArray("tags");
125     for(unsigned tagsIndex = 0; tagsIndex < tagsJsonList.GetLength(); ++tagsIndex)
126     {
127       m_tags.push_back(tagsJsonList[tagsIndex].AsObject());
128     }
129     m_tagsHasBeenSet = true;
130   }
131 
132   if(jsonValue.ValueExists("blueprintId"))
133   {
134     m_blueprintId = jsonValue.GetString("blueprintId");
135 
136     m_blueprintIdHasBeenSet = true;
137   }
138 
139   if(jsonValue.ValueExists("blueprintName"))
140   {
141     m_blueprintName = jsonValue.GetString("blueprintName");
142 
143     m_blueprintNameHasBeenSet = true;
144   }
145 
146   if(jsonValue.ValueExists("bundleId"))
147   {
148     m_bundleId = jsonValue.GetString("bundleId");
149 
150     m_bundleIdHasBeenSet = true;
151   }
152 
153   if(jsonValue.ValueExists("addOns"))
154   {
155     Array<JsonView> addOnsJsonList = jsonValue.GetArray("addOns");
156     for(unsigned addOnsIndex = 0; addOnsIndex < addOnsJsonList.GetLength(); ++addOnsIndex)
157     {
158       m_addOns.push_back(addOnsJsonList[addOnsIndex].AsObject());
159     }
160     m_addOnsHasBeenSet = true;
161   }
162 
163   if(jsonValue.ValueExists("isStaticIp"))
164   {
165     m_isStaticIp = jsonValue.GetBool("isStaticIp");
166 
167     m_isStaticIpHasBeenSet = true;
168   }
169 
170   if(jsonValue.ValueExists("privateIpAddress"))
171   {
172     m_privateIpAddress = jsonValue.GetString("privateIpAddress");
173 
174     m_privateIpAddressHasBeenSet = true;
175   }
176 
177   if(jsonValue.ValueExists("publicIpAddress"))
178   {
179     m_publicIpAddress = jsonValue.GetString("publicIpAddress");
180 
181     m_publicIpAddressHasBeenSet = true;
182   }
183 
184   if(jsonValue.ValueExists("ipv6Addresses"))
185   {
186     Array<JsonView> ipv6AddressesJsonList = jsonValue.GetArray("ipv6Addresses");
187     for(unsigned ipv6AddressesIndex = 0; ipv6AddressesIndex < ipv6AddressesJsonList.GetLength(); ++ipv6AddressesIndex)
188     {
189       m_ipv6Addresses.push_back(ipv6AddressesJsonList[ipv6AddressesIndex].AsString());
190     }
191     m_ipv6AddressesHasBeenSet = true;
192   }
193 
194   if(jsonValue.ValueExists("ipAddressType"))
195   {
196     m_ipAddressType = IpAddressTypeMapper::GetIpAddressTypeForName(jsonValue.GetString("ipAddressType"));
197 
198     m_ipAddressTypeHasBeenSet = true;
199   }
200 
201   if(jsonValue.ValueExists("hardware"))
202   {
203     m_hardware = jsonValue.GetObject("hardware");
204 
205     m_hardwareHasBeenSet = true;
206   }
207 
208   if(jsonValue.ValueExists("networking"))
209   {
210     m_networking = jsonValue.GetObject("networking");
211 
212     m_networkingHasBeenSet = true;
213   }
214 
215   if(jsonValue.ValueExists("state"))
216   {
217     m_state = jsonValue.GetObject("state");
218 
219     m_stateHasBeenSet = true;
220   }
221 
222   if(jsonValue.ValueExists("username"))
223   {
224     m_username = jsonValue.GetString("username");
225 
226     m_usernameHasBeenSet = true;
227   }
228 
229   if(jsonValue.ValueExists("sshKeyName"))
230   {
231     m_sshKeyName = jsonValue.GetString("sshKeyName");
232 
233     m_sshKeyNameHasBeenSet = true;
234   }
235 
236   return *this;
237 }
238 
Jsonize() const239 JsonValue Instance::Jsonize() const
240 {
241   JsonValue payload;
242 
243   if(m_nameHasBeenSet)
244   {
245    payload.WithString("name", m_name);
246 
247   }
248 
249   if(m_arnHasBeenSet)
250   {
251    payload.WithString("arn", m_arn);
252 
253   }
254 
255   if(m_supportCodeHasBeenSet)
256   {
257    payload.WithString("supportCode", m_supportCode);
258 
259   }
260 
261   if(m_createdAtHasBeenSet)
262   {
263    payload.WithDouble("createdAt", m_createdAt.SecondsWithMSPrecision());
264   }
265 
266   if(m_locationHasBeenSet)
267   {
268    payload.WithObject("location", m_location.Jsonize());
269 
270   }
271 
272   if(m_resourceTypeHasBeenSet)
273   {
274    payload.WithString("resourceType", ResourceTypeMapper::GetNameForResourceType(m_resourceType));
275   }
276 
277   if(m_tagsHasBeenSet)
278   {
279    Array<JsonValue> tagsJsonList(m_tags.size());
280    for(unsigned tagsIndex = 0; tagsIndex < tagsJsonList.GetLength(); ++tagsIndex)
281    {
282      tagsJsonList[tagsIndex].AsObject(m_tags[tagsIndex].Jsonize());
283    }
284    payload.WithArray("tags", std::move(tagsJsonList));
285 
286   }
287 
288   if(m_blueprintIdHasBeenSet)
289   {
290    payload.WithString("blueprintId", m_blueprintId);
291 
292   }
293 
294   if(m_blueprintNameHasBeenSet)
295   {
296    payload.WithString("blueprintName", m_blueprintName);
297 
298   }
299 
300   if(m_bundleIdHasBeenSet)
301   {
302    payload.WithString("bundleId", m_bundleId);
303 
304   }
305 
306   if(m_addOnsHasBeenSet)
307   {
308    Array<JsonValue> addOnsJsonList(m_addOns.size());
309    for(unsigned addOnsIndex = 0; addOnsIndex < addOnsJsonList.GetLength(); ++addOnsIndex)
310    {
311      addOnsJsonList[addOnsIndex].AsObject(m_addOns[addOnsIndex].Jsonize());
312    }
313    payload.WithArray("addOns", std::move(addOnsJsonList));
314 
315   }
316 
317   if(m_isStaticIpHasBeenSet)
318   {
319    payload.WithBool("isStaticIp", m_isStaticIp);
320 
321   }
322 
323   if(m_privateIpAddressHasBeenSet)
324   {
325    payload.WithString("privateIpAddress", m_privateIpAddress);
326 
327   }
328 
329   if(m_publicIpAddressHasBeenSet)
330   {
331    payload.WithString("publicIpAddress", m_publicIpAddress);
332 
333   }
334 
335   if(m_ipv6AddressesHasBeenSet)
336   {
337    Array<JsonValue> ipv6AddressesJsonList(m_ipv6Addresses.size());
338    for(unsigned ipv6AddressesIndex = 0; ipv6AddressesIndex < ipv6AddressesJsonList.GetLength(); ++ipv6AddressesIndex)
339    {
340      ipv6AddressesJsonList[ipv6AddressesIndex].AsString(m_ipv6Addresses[ipv6AddressesIndex]);
341    }
342    payload.WithArray("ipv6Addresses", std::move(ipv6AddressesJsonList));
343 
344   }
345 
346   if(m_ipAddressTypeHasBeenSet)
347   {
348    payload.WithString("ipAddressType", IpAddressTypeMapper::GetNameForIpAddressType(m_ipAddressType));
349   }
350 
351   if(m_hardwareHasBeenSet)
352   {
353    payload.WithObject("hardware", m_hardware.Jsonize());
354 
355   }
356 
357   if(m_networkingHasBeenSet)
358   {
359    payload.WithObject("networking", m_networking.Jsonize());
360 
361   }
362 
363   if(m_stateHasBeenSet)
364   {
365    payload.WithObject("state", m_state.Jsonize());
366 
367   }
368 
369   if(m_usernameHasBeenSet)
370   {
371    payload.WithString("username", m_username);
372 
373   }
374 
375   if(m_sshKeyNameHasBeenSet)
376   {
377    payload.WithString("sshKeyName", m_sshKeyName);
378 
379   }
380 
381   return payload;
382 }
383 
384 } // namespace Model
385 } // namespace Lightsail
386 } // namespace Aws
387