/*
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 ExternalDevice type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ExternalDevice{}

// ExternalDevice External device descriptor
type ExternalDevice struct {
	// ID assigned by external provider
	Id string `json:"id"`
	// Name of the device
	Name string `json:"name"`
	// Name of the external provider
	Provider string `json:"provider"`
	// Optional custom ID data
	IdData *string `json:"id_data,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _ExternalDevice ExternalDevice

// NewExternalDevice instantiates a new ExternalDevice 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 NewExternalDevice(id string, name string, provider string) *ExternalDevice {
	this := ExternalDevice{}
	this.Id = id
	this.Name = name
	this.Provider = provider
	return &this
}

// NewExternalDeviceWithDefaults instantiates a new ExternalDevice 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 NewExternalDeviceWithDefaults() *ExternalDevice {
	this := ExternalDevice{}
	return &this
}

// GetId returns the Id field value
func (o *ExternalDevice) 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 *ExternalDevice) GetIdOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Id, true
}

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

// GetName returns the Name field value
func (o *ExternalDevice) GetName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Name
}

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

// SetName sets field value
func (o *ExternalDevice) SetName(v string) {
	o.Name = v
}

// GetProvider returns the Provider field value
func (o *ExternalDevice) GetProvider() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Provider
}

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

// SetProvider sets field value
func (o *ExternalDevice) SetProvider(v string) {
	o.Provider = v
}

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

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

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

	return false
}

// SetIdData gets a reference to the given string and assigns it to the IdData field.
func (o *ExternalDevice) SetIdData(v string) {
	o.IdData = &v
}

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

func (o ExternalDevice) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["id"] = o.Id
	toSerialize["name"] = o.Name
	toSerialize["provider"] = o.Provider
	if !IsNil(o.IdData) {
		toSerialize["id_data"] = o.IdData
	}

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

	return toSerialize, nil
}

func (o *ExternalDevice) 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",
		"name",
		"provider",
	}

	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)
		}
	}

	varExternalDevice := _ExternalDevice{}

	err = json.Unmarshal(data, &varExternalDevice)

	if err != nil {
		return err
	}

	*o = ExternalDevice(varExternalDevice)

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

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

	return err
}

type NullableExternalDevice struct {
	value *ExternalDevice
	isSet bool
}

func (v NullableExternalDevice) Get() *ExternalDevice {
	return v.value
}

func (v *NullableExternalDevice) Set(val *ExternalDevice) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableExternalDevice(val *ExternalDevice) *NullableExternalDevice {
	return &NullableExternalDevice{value: val, isSet: true}
}

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

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


