/*
Mender API

Combined API specification for the features of the different Mender backend services, suitable for code generation applications 

API version: 1
Contact: support@mender.io
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package client

import (
	"encoding/json"
	"fmt"
)

// checks if the DeviceNew type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &DeviceNew{}

// DeviceNew struct for DeviceNew
type DeviceNew struct {
	// Mender-assigned unique ID.
	Id string `json:"id"`
	// Timestamp of the most recent attribute update.
	UpdatedTs *string `json:"updated_ts,omitempty"`
	// A list of attribute descriptors.
	Attributes []Attribute `json:"attributes,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _DeviceNew DeviceNew

// NewDeviceNew instantiates a new DeviceNew object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewDeviceNew(id string) *DeviceNew {
	this := DeviceNew{}
	this.Id = id
	return &this
}

// NewDeviceNewWithDefaults instantiates a new DeviceNew object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewDeviceNewWithDefaults() *DeviceNew {
	this := DeviceNew{}
	return &this
}

// GetId returns the Id field value
func (o *DeviceNew) GetId() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Id
}

// GetIdOk returns a tuple with the Id field value
// and a boolean to check if the value has been set.
func (o *DeviceNew) GetIdOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Id, true
}

// SetId sets field value
func (o *DeviceNew) SetId(v string) {
	o.Id = v
}

// GetUpdatedTs returns the UpdatedTs field value if set, zero value otherwise.
func (o *DeviceNew) GetUpdatedTs() string {
	if o == nil || IsNil(o.UpdatedTs) {
		var ret string
		return ret
	}
	return *o.UpdatedTs
}

// GetUpdatedTsOk returns a tuple with the UpdatedTs field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DeviceNew) GetUpdatedTsOk() (*string, bool) {
	if o == nil || IsNil(o.UpdatedTs) {
		return nil, false
	}
	return o.UpdatedTs, true
}

// HasUpdatedTs returns a boolean if a field has been set.
func (o *DeviceNew) HasUpdatedTs() bool {
	if o != nil && !IsNil(o.UpdatedTs) {
		return true
	}

	return false
}

// SetUpdatedTs gets a reference to the given string and assigns it to the UpdatedTs field.
func (o *DeviceNew) SetUpdatedTs(v string) {
	o.UpdatedTs = &v
}

// GetAttributes returns the Attributes field value if set, zero value otherwise.
func (o *DeviceNew) GetAttributes() []Attribute {
	if o == nil || IsNil(o.Attributes) {
		var ret []Attribute
		return ret
	}
	return o.Attributes
}

// GetAttributesOk returns a tuple with the Attributes field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *DeviceNew) GetAttributesOk() ([]Attribute, bool) {
	if o == nil || IsNil(o.Attributes) {
		return nil, false
	}
	return o.Attributes, true
}

// HasAttributes returns a boolean if a field has been set.
func (o *DeviceNew) HasAttributes() bool {
	if o != nil && !IsNil(o.Attributes) {
		return true
	}

	return false
}

// SetAttributes gets a reference to the given []Attribute and assigns it to the Attributes field.
func (o *DeviceNew) SetAttributes(v []Attribute) {
	o.Attributes = v
}

func (o DeviceNew) MarshalJSON() ([]byte, error) {
	toSerialize,err := o.ToMap()
	if err != nil {
		return []byte{}, err
	}
	return json.Marshal(toSerialize)
}

func (o DeviceNew) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["id"] = o.Id
	if !IsNil(o.UpdatedTs) {
		toSerialize["updated_ts"] = o.UpdatedTs
	}
	if !IsNil(o.Attributes) {
		toSerialize["attributes"] = o.Attributes
	}

	for key, value := range o.AdditionalProperties {
		toSerialize[key] = value
	}

	return toSerialize, nil
}

func (o *DeviceNew) UnmarshalJSON(data []byte) (err error) {
	// This validates that all required properties are included in the JSON object
	// by unmarshalling the object into a generic map with string keys and checking
	// that every required field exists as a key in the generic map.
	requiredProperties := []string{
		"id",
	}

	allProperties := make(map[string]interface{})

	err = json.Unmarshal(data, &allProperties)

	if err != nil {
		return err;
	}

	for _, requiredProperty := range(requiredProperties) {
		if _, exists := allProperties[requiredProperty]; !exists {
			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

	varDeviceNew := _DeviceNew{}

	err = json.Unmarshal(data, &varDeviceNew)

	if err != nil {
		return err
	}

	*o = DeviceNew(varDeviceNew)

	additionalProperties := make(map[string]interface{})

	if err = json.Unmarshal(data, &additionalProperties); err == nil {
		delete(additionalProperties, "id")
		delete(additionalProperties, "updated_ts")
		delete(additionalProperties, "attributes")
		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableDeviceNew struct {
	value *DeviceNew
	isSet bool
}

func (v NullableDeviceNew) Get() *DeviceNew {
	return v.value
}

func (v *NullableDeviceNew) Set(val *DeviceNew) {
	v.value = val
	v.isSet = true
}

func (v NullableDeviceNew) IsSet() bool {
	return v.isSet
}

func (v *NullableDeviceNew) Unset() {
	v.value = nil
	v.isSet = false
}

func NewNullableDeviceNew(val *DeviceNew) *NullableDeviceNew {
	return &NullableDeviceNew{value: val, isSet: true}
}

func (v NullableDeviceNew) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.value)
}

func (v *NullableDeviceNew) UnmarshalJSON(src []byte) error {
	v.isSet = true
	return json.Unmarshal(src, &v.value)
}


