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

// ErrorWithMessage operation error
type ErrorWithMessage struct {
	// error code
	ErrorCode int32 `json:"error_code"`
	// error message
	ErrorMsg string `json:"error_msg"`
}

type _ErrorWithMessage ErrorWithMessage

// NewErrorWithMessage instantiates a new ErrorWithMessage 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 NewErrorWithMessage(errorCode int32, errorMsg string) *ErrorWithMessage {
	this := ErrorWithMessage{}
	this.ErrorCode = errorCode
	this.ErrorMsg = errorMsg
	return &this
}

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

// GetErrorCode returns the ErrorCode field value
func (o *ErrorWithMessage) GetErrorCode() int32 {
	if o == nil {
		var ret int32
		return ret
	}

	return o.ErrorCode
}

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

// SetErrorCode sets field value
func (o *ErrorWithMessage) SetErrorCode(v int32) {
	o.ErrorCode = v
}

// GetErrorMsg returns the ErrorMsg field value
func (o *ErrorWithMessage) GetErrorMsg() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.ErrorMsg
}

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

// SetErrorMsg sets field value
func (o *ErrorWithMessage) SetErrorMsg(v string) {
	o.ErrorMsg = v
}

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

func (o ErrorWithMessage) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["error_code"] = o.ErrorCode
	toSerialize["error_msg"] = o.ErrorMsg
	return toSerialize, nil
}

func (o *ErrorWithMessage) 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{
		"error_code",
		"error_msg",
	}

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

	varErrorWithMessage := _ErrorWithMessage{}

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

	if err != nil {
		return err
	}

	*o = ErrorWithMessage(varErrorWithMessage)

	return err
}

type NullableErrorWithMessage struct {
	value *ErrorWithMessage
	isSet bool
}

func (v NullableErrorWithMessage) Get() *ErrorWithMessage {
	return v.value
}

func (v *NullableErrorWithMessage) Set(val *ErrorWithMessage) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableErrorWithMessage(val *ErrorWithMessage) *NullableErrorWithMessage {
	return &NullableErrorWithMessage{value: val, isSet: true}
}

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

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