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

// ClusterMaster struct for ClusterMaster
type ClusterMaster struct {
	// address of the current master node
	Addr string `json:"addr"`
	// online status of this master
	Alive bool `json:"alive"`
	// is this master the leader
	Leader bool   `json:"leader"`
	Name   string `json:"name"`
}

type _ClusterMaster ClusterMaster

// NewClusterMaster instantiates a new ClusterMaster 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 NewClusterMaster(addr string, alive bool, leader bool, name string) *ClusterMaster {
	this := ClusterMaster{}
	this.Addr = addr
	this.Alive = alive
	this.Leader = leader
	this.Name = name
	return &this
}

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

// GetAddr returns the Addr field value
func (o *ClusterMaster) GetAddr() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Addr
}

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

// SetAddr sets field value
func (o *ClusterMaster) SetAddr(v string) {
	o.Addr = v
}

// GetAlive returns the Alive field value
func (o *ClusterMaster) GetAlive() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.Alive
}

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

// SetAlive sets field value
func (o *ClusterMaster) SetAlive(v bool) {
	o.Alive = v
}

// GetLeader returns the Leader field value
func (o *ClusterMaster) GetLeader() bool {
	if o == nil {
		var ret bool
		return ret
	}

	return o.Leader
}

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

// SetLeader sets field value
func (o *ClusterMaster) SetLeader(v bool) {
	o.Leader = v
}

// GetName returns the Name field value
func (o *ClusterMaster) GetName() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Name
}

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

// SetName sets field value
func (o *ClusterMaster) SetName(v string) {
	o.Name = v
}

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

func (o ClusterMaster) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["addr"] = o.Addr
	toSerialize["alive"] = o.Alive
	toSerialize["leader"] = o.Leader
	toSerialize["name"] = o.Name
	return toSerialize, nil
}

func (o *ClusterMaster) 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{
		"addr",
		"alive",
		"leader",
		"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)
		}
	}

	varClusterMaster := _ClusterMaster{}

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

	if err != nil {
		return err
	}

	*o = ClusterMaster(varClusterMaster)

	return err
}

type NullableClusterMaster struct {
	value *ClusterMaster
	isSet bool
}

func (v NullableClusterMaster) Get() *ClusterMaster {
	return v.value
}

func (v *NullableClusterMaster) Set(val *ClusterMaster) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableClusterMaster(val *ClusterMaster) *NullableClusterMaster {
	return &NullableClusterMaster{value: val, isSet: true}
}

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

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