/*
OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

API version: 1.0.0
*/

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

package petstore

import (
	"encoding/json"
	"reflect"
	"strings"
)

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

// DuplicatedPropChild struct for DuplicatedPropChild
type DuplicatedPropChild struct {
	DuplicatedPropParent
	// A discriminator value
	DupProp *string `json:"dup-prop,omitempty"`
	AdditionalProperties map[string]interface{}
}

type _DuplicatedPropChild DuplicatedPropChild

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

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

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

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

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

	return false
}

// SetDupProp gets a reference to the given string and assigns it to the DupProp field.
func (o *DuplicatedPropChild) SetDupProp(v string) {
	o.DupProp = &v
}

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

func (o DuplicatedPropChild) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	serializedDuplicatedPropParent, errDuplicatedPropParent := json.Marshal(o.DuplicatedPropParent)
	if errDuplicatedPropParent != nil {
		return map[string]interface{}{}, errDuplicatedPropParent
	}
	errDuplicatedPropParent = json.Unmarshal([]byte(serializedDuplicatedPropParent), &toSerialize)
	if errDuplicatedPropParent != nil {
		return map[string]interface{}{}, errDuplicatedPropParent
	}
	if !IsNil(o.DupProp) {
		toSerialize["dup-prop"] = o.DupProp
	}

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

	return toSerialize, nil
}

func (o *DuplicatedPropChild) UnmarshalJSON(bytes []byte) (err error) {
	type DuplicatedPropChildWithoutEmbeddedStruct struct {
		// A discriminator value
		DupProp *string `json:"dup-prop,omitempty"`
	}

	varDuplicatedPropChildWithoutEmbeddedStruct := DuplicatedPropChildWithoutEmbeddedStruct{}

	err = json.Unmarshal(bytes, &varDuplicatedPropChildWithoutEmbeddedStruct)
	if err == nil {
		varDuplicatedPropChild := _DuplicatedPropChild{}
		varDuplicatedPropChild.DupProp = varDuplicatedPropChildWithoutEmbeddedStruct.DupProp
		*o = DuplicatedPropChild(varDuplicatedPropChild)
	} else {
		return err
	}

	varDuplicatedPropChild := _DuplicatedPropChild{}

	err = json.Unmarshal(bytes, &varDuplicatedPropChild)
	if err == nil {
		o.DuplicatedPropParent = varDuplicatedPropChild.DuplicatedPropParent
	} else {
		return err
	}

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

	if err = json.Unmarshal(bytes, &additionalProperties); err == nil {
		delete(additionalProperties, "dup-prop")

		// remove fields from embedded structs
		reflectDuplicatedPropParent := reflect.ValueOf(o.DuplicatedPropParent)
		for i := 0; i < reflectDuplicatedPropParent.Type().NumField(); i++ {
			t := reflectDuplicatedPropParent.Type().Field(i)

			if jsonTag := t.Tag.Get("json"); jsonTag != "" {
				fieldName := ""
				if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
					fieldName = jsonTag[:commaIdx]
				} else {
					fieldName = jsonTag
				}
				if fieldName != "AdditionalProperties" {
					delete(additionalProperties, fieldName)
				}
			}
		}

		o.AdditionalProperties = additionalProperties
	}

	return err
}

type NullableDuplicatedPropChild struct {
	value *DuplicatedPropChild
	isSet bool
}

func (v NullableDuplicatedPropChild) Get() *DuplicatedPropChild {
	return v.value
}

func (v *NullableDuplicatedPropChild) Set(val *DuplicatedPropChild) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableDuplicatedPropChild(val *DuplicatedPropChild) *NullableDuplicatedPropChild {
	return &NullableDuplicatedPropChild{value: val, isSet: true}
}

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

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


