|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +// Copyright 2019-Present Datadog, Inc. |
| 4 | + |
| 5 | +package datadogV2 |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + |
| 10 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 11 | +) |
| 12 | + |
| 13 | +// CostTag A Cloud Cost Management tag. |
| 14 | +type CostTag struct { |
| 15 | + // Attributes of a Cloud Cost Management tag. |
| 16 | + Attributes CostTagAttributes `json:"attributes"` |
| 17 | + // The tag identifier, equal to its `key:value` representation. |
| 18 | + Id string `json:"id"` |
| 19 | + // Type of the Cloud Cost Management tag resource. |
| 20 | + Type CostTagType `json:"type"` |
| 21 | + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct |
| 22 | + UnparsedObject map[string]interface{} `json:"-"` |
| 23 | + AdditionalProperties map[string]interface{} `json:"-"` |
| 24 | +} |
| 25 | + |
| 26 | +// NewCostTag instantiates a new CostTag object. |
| 27 | +// This constructor will assign default values to properties that have it defined, |
| 28 | +// and makes sure properties required by API are set, but the set of arguments |
| 29 | +// will change when the set of required properties is changed. |
| 30 | +func NewCostTag(attributes CostTagAttributes, id string, typeVar CostTagType) *CostTag { |
| 31 | + this := CostTag{} |
| 32 | + this.Attributes = attributes |
| 33 | + this.Id = id |
| 34 | + this.Type = typeVar |
| 35 | + return &this |
| 36 | +} |
| 37 | + |
| 38 | +// NewCostTagWithDefaults instantiates a new CostTag object. |
| 39 | +// This constructor will only assign default values to properties that have it defined, |
| 40 | +// but it doesn't guarantee that properties required by API are set. |
| 41 | +func NewCostTagWithDefaults() *CostTag { |
| 42 | + this := CostTag{} |
| 43 | + var typeVar CostTagType = COSTTAGTYPE_COST_TAG |
| 44 | + this.Type = typeVar |
| 45 | + return &this |
| 46 | +} |
| 47 | + |
| 48 | +// GetAttributes returns the Attributes field value. |
| 49 | +func (o *CostTag) GetAttributes() CostTagAttributes { |
| 50 | + if o == nil { |
| 51 | + var ret CostTagAttributes |
| 52 | + return ret |
| 53 | + } |
| 54 | + return o.Attributes |
| 55 | +} |
| 56 | + |
| 57 | +// GetAttributesOk returns a tuple with the Attributes field value |
| 58 | +// and a boolean to check if the value has been set. |
| 59 | +func (o *CostTag) GetAttributesOk() (*CostTagAttributes, bool) { |
| 60 | + if o == nil { |
| 61 | + return nil, false |
| 62 | + } |
| 63 | + return &o.Attributes, true |
| 64 | +} |
| 65 | + |
| 66 | +// SetAttributes sets field value. |
| 67 | +func (o *CostTag) SetAttributes(v CostTagAttributes) { |
| 68 | + o.Attributes = v |
| 69 | +} |
| 70 | + |
| 71 | +// GetId returns the Id field value. |
| 72 | +func (o *CostTag) GetId() string { |
| 73 | + if o == nil { |
| 74 | + var ret string |
| 75 | + return ret |
| 76 | + } |
| 77 | + return o.Id |
| 78 | +} |
| 79 | + |
| 80 | +// GetIdOk returns a tuple with the Id field value |
| 81 | +// and a boolean to check if the value has been set. |
| 82 | +func (o *CostTag) GetIdOk() (*string, bool) { |
| 83 | + if o == nil { |
| 84 | + return nil, false |
| 85 | + } |
| 86 | + return &o.Id, true |
| 87 | +} |
| 88 | + |
| 89 | +// SetId sets field value. |
| 90 | +func (o *CostTag) SetId(v string) { |
| 91 | + o.Id = v |
| 92 | +} |
| 93 | + |
| 94 | +// GetType returns the Type field value. |
| 95 | +func (o *CostTag) GetType() CostTagType { |
| 96 | + if o == nil { |
| 97 | + var ret CostTagType |
| 98 | + return ret |
| 99 | + } |
| 100 | + return o.Type |
| 101 | +} |
| 102 | + |
| 103 | +// GetTypeOk returns a tuple with the Type field value |
| 104 | +// and a boolean to check if the value has been set. |
| 105 | +func (o *CostTag) GetTypeOk() (*CostTagType, bool) { |
| 106 | + if o == nil { |
| 107 | + return nil, false |
| 108 | + } |
| 109 | + return &o.Type, true |
| 110 | +} |
| 111 | + |
| 112 | +// SetType sets field value. |
| 113 | +func (o *CostTag) SetType(v CostTagType) { |
| 114 | + o.Type = v |
| 115 | +} |
| 116 | + |
| 117 | +// MarshalJSON serializes the struct using spec logic. |
| 118 | +func (o CostTag) MarshalJSON() ([]byte, error) { |
| 119 | + toSerialize := map[string]interface{}{} |
| 120 | + if o.UnparsedObject != nil { |
| 121 | + return datadog.Marshal(o.UnparsedObject) |
| 122 | + } |
| 123 | + toSerialize["attributes"] = o.Attributes |
| 124 | + toSerialize["id"] = o.Id |
| 125 | + toSerialize["type"] = o.Type |
| 126 | + |
| 127 | + for key, value := range o.AdditionalProperties { |
| 128 | + toSerialize[key] = value |
| 129 | + } |
| 130 | + return datadog.Marshal(toSerialize) |
| 131 | +} |
| 132 | + |
| 133 | +// UnmarshalJSON deserializes the given payload. |
| 134 | +func (o *CostTag) UnmarshalJSON(bytes []byte) (err error) { |
| 135 | + all := struct { |
| 136 | + Attributes *CostTagAttributes `json:"attributes"` |
| 137 | + Id *string `json:"id"` |
| 138 | + Type *CostTagType `json:"type"` |
| 139 | + }{} |
| 140 | + if err = datadog.Unmarshal(bytes, &all); err != nil { |
| 141 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 142 | + } |
| 143 | + if all.Attributes == nil { |
| 144 | + return fmt.Errorf("required field attributes missing") |
| 145 | + } |
| 146 | + if all.Id == nil { |
| 147 | + return fmt.Errorf("required field id missing") |
| 148 | + } |
| 149 | + if all.Type == nil { |
| 150 | + return fmt.Errorf("required field type missing") |
| 151 | + } |
| 152 | + additionalProperties := make(map[string]interface{}) |
| 153 | + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { |
| 154 | + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "id", "type"}) |
| 155 | + } else { |
| 156 | + return err |
| 157 | + } |
| 158 | + |
| 159 | + hasInvalidField := false |
| 160 | + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { |
| 161 | + hasInvalidField = true |
| 162 | + } |
| 163 | + o.Attributes = *all.Attributes |
| 164 | + o.Id = *all.Id |
| 165 | + if !all.Type.IsValid() { |
| 166 | + hasInvalidField = true |
| 167 | + } else { |
| 168 | + o.Type = *all.Type |
| 169 | + } |
| 170 | + |
| 171 | + if len(additionalProperties) > 0 { |
| 172 | + o.AdditionalProperties = additionalProperties |
| 173 | + } |
| 174 | + |
| 175 | + if hasInvalidField { |
| 176 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 177 | + } |
| 178 | + |
| 179 | + return nil |
| 180 | +} |
0 commit comments