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

// TaskTargetDataBase downstream database configuration
type TaskTargetDataBase struct {
	// source address
	Host string `json:"host"`
	// source password
	Password string `json:"password"`
	// source port
	Port     int32            `json:"port"`
	Security NullableSecurity `json:"security,omitempty"`
	// source username
	User string `json:"user"`
}

type _TaskTargetDataBase TaskTargetDataBase

// NewTaskTargetDataBase instantiates a new TaskTargetDataBase 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 NewTaskTargetDataBase(host string, password string, port int32, user string) *TaskTargetDataBase {
	this := TaskTargetDataBase{}
	this.Host = host
	this.Password = password
	this.Port = port
	this.User = user
	return &this
}

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

// GetHost returns the Host field value
func (o *TaskTargetDataBase) 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 *TaskTargetDataBase) GetHostOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Host, true
}

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

// GetPassword returns the Password field value
func (o *TaskTargetDataBase) GetPassword() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Password
}

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

// SetPassword sets field value
func (o *TaskTargetDataBase) SetPassword(v string) {
	o.Password = v
}

// GetPort returns the Port field value
func (o *TaskTargetDataBase) 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 *TaskTargetDataBase) GetPortOk() (*int32, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Port, true
}

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

// GetSecurity returns the Security field value if set, zero value otherwise (both if not set or set to explicit null).
func (o *TaskTargetDataBase) 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 *TaskTargetDataBase) 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 *TaskTargetDataBase) 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 *TaskTargetDataBase) SetSecurity(v Security) {
	o.Security.Set(&v)
}

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

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

// GetUser returns the User field value
func (o *TaskTargetDataBase) 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 *TaskTargetDataBase) GetUserOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.User, true
}

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

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

func (o TaskTargetDataBase) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["host"] = o.Host
	toSerialize["password"] = o.Password
	toSerialize["port"] = o.Port
	if o.Security.IsSet() {
		toSerialize["security"] = o.Security.Get()
	}
	toSerialize["user"] = o.User
	return toSerialize, nil
}

func (o *TaskTargetDataBase) 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{
		"host",
		"password",
		"port",
		"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)
		}
	}

	varTaskTargetDataBase := _TaskTargetDataBase{}

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

	if err != nil {
		return err
	}

	*o = TaskTargetDataBase(varTaskTargetDataBase)

	return err
}

type NullableTaskTargetDataBase struct {
	value *TaskTargetDataBase
	isSet bool
}

func (v NullableTaskTargetDataBase) Get() *TaskTargetDataBase {
	return v.value
}

func (v *NullableTaskTargetDataBase) Set(val *TaskTargetDataBase) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableTaskTargetDataBase(val *TaskTargetDataBase) *NullableTaskTargetDataBase {
	return &NullableTaskTargetDataBase{value: val, isSet: true}
}

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

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