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

// SourceStatus source status
type SourceStatus struct {
	// error message when something wrong
	ErrorMsg    *string      `json:"error_msg,omitempty"`
	RelayStatus *RelayStatus `json:"relay_status,omitempty"`
	// source name
	SourceName string `json:"source_name"`
	// The worker currently bound to the source
	WorkerName string `json:"worker_name"`
}

type _SourceStatus SourceStatus

// NewSourceStatus instantiates a new SourceStatus 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 NewSourceStatus(sourceName string, workerName string) *SourceStatus {
	this := SourceStatus{}
	this.SourceName = sourceName
	this.WorkerName = workerName
	return &this
}

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

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

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

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

	return false
}

// SetErrorMsg gets a reference to the given string and assigns it to the ErrorMsg field.
func (o *SourceStatus) SetErrorMsg(v string) {
	o.ErrorMsg = &v
}

// GetRelayStatus returns the RelayStatus field value if set, zero value otherwise.
func (o *SourceStatus) GetRelayStatus() RelayStatus {
	if o == nil || IsNil(o.RelayStatus) {
		var ret RelayStatus
		return ret
	}
	return *o.RelayStatus
}

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

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

	return false
}

// SetRelayStatus gets a reference to the given RelayStatus and assigns it to the RelayStatus field.
func (o *SourceStatus) SetRelayStatus(v RelayStatus) {
	o.RelayStatus = &v
}

// GetSourceName returns the SourceName field value
func (o *SourceStatus) GetSourceName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.SourceName
}

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

// SetSourceName sets field value
func (o *SourceStatus) SetSourceName(v string) {
	o.SourceName = v
}

// GetWorkerName returns the WorkerName field value
func (o *SourceStatus) GetWorkerName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.WorkerName
}

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

// SetWorkerName sets field value
func (o *SourceStatus) SetWorkerName(v string) {
	o.WorkerName = v
}

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

func (o SourceStatus) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	if !IsNil(o.ErrorMsg) {
		toSerialize["error_msg"] = o.ErrorMsg
	}
	if !IsNil(o.RelayStatus) {
		toSerialize["relay_status"] = o.RelayStatus
	}
	toSerialize["source_name"] = o.SourceName
	toSerialize["worker_name"] = o.WorkerName
	return toSerialize, nil
}

func (o *SourceStatus) 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_name",
		"worker_name",
	}

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

	varSourceStatus := _SourceStatus{}

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

	if err != nil {
		return err
	}

	*o = SourceStatus(varSourceStatus)

	return err
}

type NullableSourceStatus struct {
	value *SourceStatus
	isSet bool
}

func (v NullableSourceStatus) Get() *SourceStatus {
	return v.value
}

func (v *NullableSourceStatus) Set(val *SourceStatus) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableSourceStatus(val *SourceStatus) *NullableSourceStatus {
	return &NullableSourceStatus{value: val, isSet: true}
}

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

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