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

// Source source
type Source struct {
	// whether this source is enabled
	Enable bool `json:"enable"`
	// whether to use GTID to pull binlogs from upstream
	EnableGtid bool `json:"enable_gtid"`
	// flavor of this source
	Flavor *string `json:"flavor,omitempty"`
	// source address
	Host string `json:"host"`
	// source password
	Password NullableString `json:"password,omitempty"`
	// source port
	Port        int32            `json:"port"`
	Purge       *Purge           `json:"purge,omitempty"`
	RelayConfig *RelayConfig     `json:"relay_config,omitempty"`
	Security    NullableSecurity `json:"security,omitempty"`
	// source name
	SourceName string         `json:"source_name"`
	StatusList []SourceStatus `json:"status_list,omitempty"`
	// task name list
	TaskNameList []string `json:"task_name_list,omitempty"`
	// source username
	User string `json:"user"`
}

type _Source Source

// NewSource instantiates a new Source 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 NewSource(enable bool, enableGtid bool, host string, port int32, sourceName string, user string) *Source {
	this := Source{}
	this.Enable = enable
	this.EnableGtid = enableGtid
	this.Host = host
	this.Port = port
	this.SourceName = sourceName
	this.User = user
	return &this
}

// NewSourceWithDefaults instantiates a new Source 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 NewSourceWithDefaults() *Source {
	this := Source{}
	var enable bool = false
	this.Enable = enable
	var enableGtid bool = false
	this.EnableGtid = enableGtid
	return &this
}

// GetEnable returns the Enable field value
func (o *Source) GetEnable() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.Enable
}

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

// SetEnable sets field value
func (o *Source) SetEnable(v bool) {
	o.Enable = v
}

// GetEnableGtid returns the EnableGtid field value
func (o *Source) GetEnableGtid() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.EnableGtid
}

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

// SetEnableGtid sets field value
func (o *Source) SetEnableGtid(v bool) {
	o.EnableGtid = v
}

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

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

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

	return false
}

// SetFlavor gets a reference to the given string and assigns it to the Flavor field.
func (o *Source) SetFlavor(v string) {
	o.Flavor = &v
}

// GetHost returns the Host field value
func (o *Source) GetHost() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Host
}

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

// SetHost sets field value
func (o *Source) SetHost(v string) {
	o.Host = v
}

// GetPassword returns the Password field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *Source) GetPassword() string {
	if o == nil || IsNil(o.Password.Get()) {
		var ret string
		return ret
	}
	return *o.Password.Get()
}

// GetPasswordOk returns a tuple with the Password field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *Source) GetPasswordOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return o.Password.Get(), o.Password.IsSet()
}

// HasPassword returns a boolean if a field has been set.
func (o *Source) HasPassword() bool {
	if o != nil && o.Password.IsSet() {
		return true
	}

	return false
}

// SetPassword gets a reference to the given NullableString and assigns it to the Password field.
func (o *Source) SetPassword(v string) {
	o.Password.Set(&v)
}

// SetPasswordNil sets the value for Password to be an explicit nil
func (o *Source) SetPasswordNil() {
	o.Password.Set(nil)
}

// UnsetPassword ensures that no value is present for Password, not even an explicit nil
func (o *Source) UnsetPassword() {
	o.Password.Unset()
}

// GetPort returns the Port field value
func (o *Source) GetPort() int32 {
	if o == nil {
		var ret int32
		return ret
	}

	return o.Port
}

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

// SetPort sets field value
func (o *Source) SetPort(v int32) {
	o.Port = v
}

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

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

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

	return false
}

// SetPurge gets a reference to the given Purge and assigns it to the Purge field.
func (o *Source) SetPurge(v Purge) {
	o.Purge = &v
}

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

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

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

	return false
}

// SetRelayConfig gets a reference to the given RelayConfig and assigns it to the RelayConfig field.
func (o *Source) SetRelayConfig(v RelayConfig) {
	o.RelayConfig = &v
}

// GetSecurity returns the Security field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *Source) GetSecurity() Security {
	if o == nil || IsNil(o.Security.Get()) {
		var ret Security
		return ret
	}
	return *o.Security.Get()
}

// GetSecurityOk returns a tuple with the Security field value if set, nil otherwise
// and a boolean to check if the value has been set.
// NOTE: If the value is an explicit nil, `nil, true` will be returned
func (o *Source) GetSecurityOk() (*Security, bool) {
	if o == nil {
		return nil, false
	}
	return o.Security.Get(), o.Security.IsSet()
}

// HasSecurity returns a boolean if a field has been set.
func (o *Source) HasSecurity() bool {
	if o != nil && o.Security.IsSet() {
		return true
	}

	return false
}

// SetSecurity gets a reference to the given NullableSecurity and assigns it to the Security field.
func (o *Source) SetSecurity(v Security) {
	o.Security.Set(&v)
}

// SetSecurityNil sets the value for Security to be an explicit nil
func (o *Source) SetSecurityNil() {
	o.Security.Set(nil)
}

// UnsetSecurity ensures that no value is present for Security, not even an explicit nil
func (o *Source) UnsetSecurity() {
	o.Security.Unset()
}

// GetSourceName returns the SourceName field value
func (o *Source) 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 *Source) GetSourceNameOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.SourceName, true
}

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

// GetStatusList returns the StatusList field value if set, zero value otherwise.
func (o *Source) GetStatusList() []SourceStatus {
	if o == nil || IsNil(o.StatusList) {
		var ret []SourceStatus
		return ret
	}
	return o.StatusList
}

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

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

	return false
}

// SetStatusList gets a reference to the given []SourceStatus and assigns it to the StatusList field.
func (o *Source) SetStatusList(v []SourceStatus) {
	o.StatusList = v
}

// GetTaskNameList returns the TaskNameList field value if set, zero value otherwise.
func (o *Source) GetTaskNameList() []string {
	if o == nil || IsNil(o.TaskNameList) {
		var ret []string
		return ret
	}
	return o.TaskNameList
}

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

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

	return false
}

// SetTaskNameList gets a reference to the given []string and assigns it to the TaskNameList field.
func (o *Source) SetTaskNameList(v []string) {
	o.TaskNameList = v
}

// GetUser returns the User field value
func (o *Source) GetUser() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.User
}

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

// SetUser sets field value
func (o *Source) SetUser(v string) {
	o.User = v
}

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

func (o Source) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["enable"] = o.Enable
	toSerialize["enable_gtid"] = o.EnableGtid
	if !IsNil(o.Flavor) {
		toSerialize["flavor"] = o.Flavor
	}
	toSerialize["host"] = o.Host
	if o.Password.IsSet() {
		toSerialize["password"] = o.Password.Get()
	}
	toSerialize["port"] = o.Port
	if !IsNil(o.Purge) {
		toSerialize["purge"] = o.Purge
	}
	if !IsNil(o.RelayConfig) {
		toSerialize["relay_config"] = o.RelayConfig
	}
	if o.Security.IsSet() {
		toSerialize["security"] = o.Security.Get()
	}
	toSerialize["source_name"] = o.SourceName
	if !IsNil(o.StatusList) {
		toSerialize["status_list"] = o.StatusList
	}
	if !IsNil(o.TaskNameList) {
		toSerialize["task_name_list"] = o.TaskNameList
	}
	toSerialize["user"] = o.User
	return toSerialize, nil
}

func (o *Source) 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{
		"enable",
		"enable_gtid",
		"host",
		"port",
		"source_name",
		"user",
	}

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

	varSource := _Source{}

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

	if err != nil {
		return err
	}

	*o = Source(varSource)

	return err
}

type NullableSource struct {
	value *Source
	isSet bool
}

func (v NullableSource) Get() *Source {
	return v.value
}

func (v *NullableSource) Set(val *Source) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableSource(val *Source) *NullableSource {
	return &NullableSource{value: val, isSet: true}
}

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

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