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/Disk.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 
Disk()21 Disk::Disk() :
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_addOnsHasBeenSet(false),
31     m_sizeInGb(0),
32     m_sizeInGbHasBeenSet(false),
33     m_isSystemDisk(false),
34     m_isSystemDiskHasBeenSet(false),
35     m_iops(0),
36     m_iopsHasBeenSet(false),
37     m_pathHasBeenSet(false),
38     m_state(DiskState::NOT_SET),
39     m_stateHasBeenSet(false),
40     m_attachedToHasBeenSet(false),
41     m_isAttached(false),
42     m_isAttachedHasBeenSet(false)
43 {
44 }
45 
Disk(JsonView jsonValue)46 Disk::Disk(JsonView jsonValue) :
47     m_nameHasBeenSet(false),
48     m_arnHasBeenSet(false),
49     m_supportCodeHasBeenSet(false),
50     m_createdAtHasBeenSet(false),
51     m_locationHasBeenSet(false),
52     m_resourceType(ResourceType::NOT_SET),
53     m_resourceTypeHasBeenSet(false),
54     m_tagsHasBeenSet(false),
55     m_addOnsHasBeenSet(false),
56     m_sizeInGb(0),
57     m_sizeInGbHasBeenSet(false),
58     m_isSystemDisk(false),
59     m_isSystemDiskHasBeenSet(false),
60     m_iops(0),
61     m_iopsHasBeenSet(false),
62     m_pathHasBeenSet(false),
63     m_state(DiskState::NOT_SET),
64     m_stateHasBeenSet(false),
65     m_attachedToHasBeenSet(false),
66     m_isAttached(false),
67     m_isAttachedHasBeenSet(false)
68 {
69   *this = jsonValue;
70 }
71 
operator =(JsonView jsonValue)72 Disk& Disk::operator =(JsonView jsonValue)
73 {
74   if(jsonValue.ValueExists("name"))
75   {
76     m_name = jsonValue.GetString("name");
77 
78     m_nameHasBeenSet = true;
79   }
80 
81   if(jsonValue.ValueExists("arn"))
82   {
83     m_arn = jsonValue.GetString("arn");
84 
85     m_arnHasBeenSet = true;
86   }
87 
88   if(jsonValue.ValueExists("supportCode"))
89   {
90     m_supportCode = jsonValue.GetString("supportCode");
91 
92     m_supportCodeHasBeenSet = true;
93   }
94 
95   if(jsonValue.ValueExists("createdAt"))
96   {
97     m_createdAt = jsonValue.GetDouble("createdAt");
98 
99     m_createdAtHasBeenSet = true;
100   }
101 
102   if(jsonValue.ValueExists("location"))
103   {
104     m_location = jsonValue.GetObject("location");
105 
106     m_locationHasBeenSet = true;
107   }
108 
109   if(jsonValue.ValueExists("resourceType"))
110   {
111     m_resourceType = ResourceTypeMapper::GetResourceTypeForName(jsonValue.GetString("resourceType"));
112 
113     m_resourceTypeHasBeenSet = true;
114   }
115 
116   if(jsonValue.ValueExists("tags"))
117   {
118     Array<JsonView> tagsJsonList = jsonValue.GetArray("tags");
119     for(unsigned tagsIndex = 0; tagsIndex < tagsJsonList.GetLength(); ++tagsIndex)
120     {
121       m_tags.push_back(tagsJsonList[tagsIndex].AsObject());
122     }
123     m_tagsHasBeenSet = true;
124   }
125 
126   if(jsonValue.ValueExists("addOns"))
127   {
128     Array<JsonView> addOnsJsonList = jsonValue.GetArray("addOns");
129     for(unsigned addOnsIndex = 0; addOnsIndex < addOnsJsonList.GetLength(); ++addOnsIndex)
130     {
131       m_addOns.push_back(addOnsJsonList[addOnsIndex].AsObject());
132     }
133     m_addOnsHasBeenSet = true;
134   }
135 
136   if(jsonValue.ValueExists("sizeInGb"))
137   {
138     m_sizeInGb = jsonValue.GetInteger("sizeInGb");
139 
140     m_sizeInGbHasBeenSet = true;
141   }
142 
143   if(jsonValue.ValueExists("isSystemDisk"))
144   {
145     m_isSystemDisk = jsonValue.GetBool("isSystemDisk");
146 
147     m_isSystemDiskHasBeenSet = true;
148   }
149 
150   if(jsonValue.ValueExists("iops"))
151   {
152     m_iops = jsonValue.GetInteger("iops");
153 
154     m_iopsHasBeenSet = true;
155   }
156 
157   if(jsonValue.ValueExists("path"))
158   {
159     m_path = jsonValue.GetString("path");
160 
161     m_pathHasBeenSet = true;
162   }
163 
164   if(jsonValue.ValueExists("state"))
165   {
166     m_state = DiskStateMapper::GetDiskStateForName(jsonValue.GetString("state"));
167 
168     m_stateHasBeenSet = true;
169   }
170 
171   if(jsonValue.ValueExists("attachedTo"))
172   {
173     m_attachedTo = jsonValue.GetString("attachedTo");
174 
175     m_attachedToHasBeenSet = true;
176   }
177 
178   if(jsonValue.ValueExists("isAttached"))
179   {
180     m_isAttached = jsonValue.GetBool("isAttached");
181 
182     m_isAttachedHasBeenSet = true;
183   }
184 
185   return *this;
186 }
187 
Jsonize() const188 JsonValue Disk::Jsonize() const
189 {
190   JsonValue payload;
191 
192   if(m_nameHasBeenSet)
193   {
194    payload.WithString("name", m_name);
195 
196   }
197 
198   if(m_arnHasBeenSet)
199   {
200    payload.WithString("arn", m_arn);
201 
202   }
203 
204   if(m_supportCodeHasBeenSet)
205   {
206    payload.WithString("supportCode", m_supportCode);
207 
208   }
209 
210   if(m_createdAtHasBeenSet)
211   {
212    payload.WithDouble("createdAt", m_createdAt.SecondsWithMSPrecision());
213   }
214 
215   if(m_locationHasBeenSet)
216   {
217    payload.WithObject("location", m_location.Jsonize());
218 
219   }
220 
221   if(m_resourceTypeHasBeenSet)
222   {
223    payload.WithString("resourceType", ResourceTypeMapper::GetNameForResourceType(m_resourceType));
224   }
225 
226   if(m_tagsHasBeenSet)
227   {
228    Array<JsonValue> tagsJsonList(m_tags.size());
229    for(unsigned tagsIndex = 0; tagsIndex < tagsJsonList.GetLength(); ++tagsIndex)
230    {
231      tagsJsonList[tagsIndex].AsObject(m_tags[tagsIndex].Jsonize());
232    }
233    payload.WithArray("tags", std::move(tagsJsonList));
234 
235   }
236 
237   if(m_addOnsHasBeenSet)
238   {
239    Array<JsonValue> addOnsJsonList(m_addOns.size());
240    for(unsigned addOnsIndex = 0; addOnsIndex < addOnsJsonList.GetLength(); ++addOnsIndex)
241    {
242      addOnsJsonList[addOnsIndex].AsObject(m_addOns[addOnsIndex].Jsonize());
243    }
244    payload.WithArray("addOns", std::move(addOnsJsonList));
245 
246   }
247 
248   if(m_sizeInGbHasBeenSet)
249   {
250    payload.WithInteger("sizeInGb", m_sizeInGb);
251 
252   }
253 
254   if(m_isSystemDiskHasBeenSet)
255   {
256    payload.WithBool("isSystemDisk", m_isSystemDisk);
257 
258   }
259 
260   if(m_iopsHasBeenSet)
261   {
262    payload.WithInteger("iops", m_iops);
263 
264   }
265 
266   if(m_pathHasBeenSet)
267   {
268    payload.WithString("path", m_path);
269 
270   }
271 
272   if(m_stateHasBeenSet)
273   {
274    payload.WithString("state", DiskStateMapper::GetNameForDiskState(m_state));
275   }
276 
277   if(m_attachedToHasBeenSet)
278   {
279    payload.WithString("attachedTo", m_attachedTo);
280 
281   }
282 
283   if(m_isAttachedHasBeenSet)
284   {
285    payload.WithBool("isAttached", m_isAttached);
286 
287   }
288 
289   return payload;
290 }
291 
292 } // namespace Model
293 } // namespace Lightsail
294 } // namespace Aws
295