1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/codedeploy/model/LambdaTarget.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 CodeDeploy
17 {
18 namespace Model
19 {
20 
LambdaTarget()21 LambdaTarget::LambdaTarget() :
22     m_deploymentIdHasBeenSet(false),
23     m_targetIdHasBeenSet(false),
24     m_targetArnHasBeenSet(false),
25     m_status(TargetStatus::NOT_SET),
26     m_statusHasBeenSet(false),
27     m_lastUpdatedAtHasBeenSet(false),
28     m_lifecycleEventsHasBeenSet(false),
29     m_lambdaFunctionInfoHasBeenSet(false)
30 {
31 }
32 
LambdaTarget(JsonView jsonValue)33 LambdaTarget::LambdaTarget(JsonView jsonValue) :
34     m_deploymentIdHasBeenSet(false),
35     m_targetIdHasBeenSet(false),
36     m_targetArnHasBeenSet(false),
37     m_status(TargetStatus::NOT_SET),
38     m_statusHasBeenSet(false),
39     m_lastUpdatedAtHasBeenSet(false),
40     m_lifecycleEventsHasBeenSet(false),
41     m_lambdaFunctionInfoHasBeenSet(false)
42 {
43   *this = jsonValue;
44 }
45 
operator =(JsonView jsonValue)46 LambdaTarget& LambdaTarget::operator =(JsonView jsonValue)
47 {
48   if(jsonValue.ValueExists("deploymentId"))
49   {
50     m_deploymentId = jsonValue.GetString("deploymentId");
51 
52     m_deploymentIdHasBeenSet = true;
53   }
54 
55   if(jsonValue.ValueExists("targetId"))
56   {
57     m_targetId = jsonValue.GetString("targetId");
58 
59     m_targetIdHasBeenSet = true;
60   }
61 
62   if(jsonValue.ValueExists("targetArn"))
63   {
64     m_targetArn = jsonValue.GetString("targetArn");
65 
66     m_targetArnHasBeenSet = true;
67   }
68 
69   if(jsonValue.ValueExists("status"))
70   {
71     m_status = TargetStatusMapper::GetTargetStatusForName(jsonValue.GetString("status"));
72 
73     m_statusHasBeenSet = true;
74   }
75 
76   if(jsonValue.ValueExists("lastUpdatedAt"))
77   {
78     m_lastUpdatedAt = jsonValue.GetDouble("lastUpdatedAt");
79 
80     m_lastUpdatedAtHasBeenSet = true;
81   }
82 
83   if(jsonValue.ValueExists("lifecycleEvents"))
84   {
85     Array<JsonView> lifecycleEventsJsonList = jsonValue.GetArray("lifecycleEvents");
86     for(unsigned lifecycleEventsIndex = 0; lifecycleEventsIndex < lifecycleEventsJsonList.GetLength(); ++lifecycleEventsIndex)
87     {
88       m_lifecycleEvents.push_back(lifecycleEventsJsonList[lifecycleEventsIndex].AsObject());
89     }
90     m_lifecycleEventsHasBeenSet = true;
91   }
92 
93   if(jsonValue.ValueExists("lambdaFunctionInfo"))
94   {
95     m_lambdaFunctionInfo = jsonValue.GetObject("lambdaFunctionInfo");
96 
97     m_lambdaFunctionInfoHasBeenSet = true;
98   }
99 
100   return *this;
101 }
102 
Jsonize() const103 JsonValue LambdaTarget::Jsonize() const
104 {
105   JsonValue payload;
106 
107   if(m_deploymentIdHasBeenSet)
108   {
109    payload.WithString("deploymentId", m_deploymentId);
110 
111   }
112 
113   if(m_targetIdHasBeenSet)
114   {
115    payload.WithString("targetId", m_targetId);
116 
117   }
118 
119   if(m_targetArnHasBeenSet)
120   {
121    payload.WithString("targetArn", m_targetArn);
122 
123   }
124 
125   if(m_statusHasBeenSet)
126   {
127    payload.WithString("status", TargetStatusMapper::GetNameForTargetStatus(m_status));
128   }
129 
130   if(m_lastUpdatedAtHasBeenSet)
131   {
132    payload.WithDouble("lastUpdatedAt", m_lastUpdatedAt.SecondsWithMSPrecision());
133   }
134 
135   if(m_lifecycleEventsHasBeenSet)
136   {
137    Array<JsonValue> lifecycleEventsJsonList(m_lifecycleEvents.size());
138    for(unsigned lifecycleEventsIndex = 0; lifecycleEventsIndex < lifecycleEventsJsonList.GetLength(); ++lifecycleEventsIndex)
139    {
140      lifecycleEventsJsonList[lifecycleEventsIndex].AsObject(m_lifecycleEvents[lifecycleEventsIndex].Jsonize());
141    }
142    payload.WithArray("lifecycleEvents", std::move(lifecycleEventsJsonList));
143 
144   }
145 
146   if(m_lambdaFunctionInfoHasBeenSet)
147   {
148    payload.WithObject("lambdaFunctionInfo", m_lambdaFunctionInfo.Jsonize());
149 
150   }
151 
152   return payload;
153 }
154 
155 } // namespace Model
156 } // namespace CodeDeploy
157 } // namespace Aws
158