/*
Merlin

API Guide for accessing Merlin's model management, deployment, and serving functionalities

API version: 0.14.0
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package client

import (
	"encoding/json"
	"fmt"
)

// checks if the AutoscalingPolicy type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &AutoscalingPolicy{}

// AutoscalingPolicy struct for AutoscalingPolicy
type AutoscalingPolicy struct {
	MetricsType MetricsType `json:"metrics_type"`
	TargetValue float32     `json:"target_value"`
}

type _AutoscalingPolicy AutoscalingPolicy

// NewAutoscalingPolicy instantiates a new AutoscalingPolicy 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 NewAutoscalingPolicy(metricsType MetricsType, targetValue float32) *AutoscalingPolicy {
	this := AutoscalingPolicy{}
	this.MetricsType = metricsType
	this.TargetValue = targetValue
	return &this
}

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

// GetMetricsType returns the MetricsType field value
func (o *AutoscalingPolicy) GetMetricsType() MetricsType {
	if o == nil {
		var ret MetricsType
		return ret
	}

	return o.MetricsType
}

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

// SetMetricsType sets field value
func (o *AutoscalingPolicy) SetMetricsType(v MetricsType) {
	o.MetricsType = v
}

// GetTargetValue returns the TargetValue field value
func (o *AutoscalingPolicy) GetTargetValue() float32 {
	if o == nil {
		var ret float32
		return ret
	}

	return o.TargetValue
}

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

// SetTargetValue sets field value
func (o *AutoscalingPolicy) SetTargetValue(v float32) {
	o.TargetValue = v
}

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

func (o AutoscalingPolicy) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["metrics_type"] = o.MetricsType
	toSerialize["target_value"] = o.TargetValue
	return toSerialize, nil
}

func (o *AutoscalingPolicy) UnmarshalJSON(bytes []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{
		"metrics_type",
		"target_value",
	}

	allProperties := make(map[string]interface{})

	err = json.Unmarshal(bytes, &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)
		}
	}

	varAutoscalingPolicy := _AutoscalingPolicy{}

	err = json.Unmarshal(bytes, &varAutoscalingPolicy)

	if err != nil {
		return err
	}

	*o = AutoscalingPolicy(varAutoscalingPolicy)

	return err
}

type NullableAutoscalingPolicy struct {
	value *AutoscalingPolicy
	isSet bool
}

func (v NullableAutoscalingPolicy) Get() *AutoscalingPolicy {
	return v.value
}

func (v *NullableAutoscalingPolicy) Set(val *AutoscalingPolicy) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableAutoscalingPolicy(val *AutoscalingPolicy) *NullableAutoscalingPolicy {
	return &NullableAutoscalingPolicy{value: val, isSet: true}
}

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

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