/*
DM OpenAPI DOC

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

API version: 6.0.0
*/

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

package dm

import (
	"bytes"
	"encoding/json"
	"fmt"
)

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

// CreateSourceRequest struct for CreateSourceRequest
type CreateSourceRequest struct {
	Source     Source  `json:"source"`
	WorkerName *string `json:"worker_name,omitempty"`
}

type _CreateSourceRequest CreateSourceRequest

// NewCreateSourceRequest instantiates a new CreateSourceRequest 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 NewCreateSourceRequest(source Source) *CreateSourceRequest {
	this := CreateSourceRequest{}
	this.Source = source
	return &this
}

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

// GetSource returns the Source field value
func (o *CreateSourceRequest) GetSource() Source {
	if o == nil {
		var ret Source
		return ret
	}

	return o.Source
}

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

// SetSource sets field value
func (o *CreateSourceRequest) SetSource(v Source) {
	o.Source = v
}

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

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

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

	return false
}

// SetWorkerName gets a reference to the given string and assigns it to the WorkerName field.
func (o *CreateSourceRequest) SetWorkerName(v string) {
	o.WorkerName = &v
}

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

func (o CreateSourceRequest) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["source"] = o.Source
	if !IsNil(o.WorkerName) {
		toSerialize["worker_name"] = o.WorkerName
	}
	return toSerialize, nil
}

func (o *CreateSourceRequest) 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{
		"source",
	}

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

	varCreateSourceRequest := _CreateSourceRequest{}

	decoder := json.NewDecoder(bytes.NewReader(data))
	decoder.DisallowUnknownFields()
	err = decoder.Decode(&varCreateSourceRequest)

	if err != nil {
		return err
	}

	*o = CreateSourceRequest(varCreateSourceRequest)

	return err
}

type NullableCreateSourceRequest struct {
	value *CreateSourceRequest
	isSet bool
}

func (v NullableCreateSourceRequest) Get() *CreateSourceRequest {
	return v.value
}

func (v *NullableCreateSourceRequest) Set(val *CreateSourceRequest) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableCreateSourceRequest(val *CreateSourceRequest) *NullableCreateSourceRequest {
	return &NullableCreateSourceRequest{value: val, isSet: true}
}

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

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