/*
Edge Firewall API

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

API version: 2.0.0
*/

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

package edgefirewall

import (
	"encoding/json"
	"fmt"
)

// SetRateLimitBehaviorArgumentAverageRateLimit - struct for SetRateLimitBehaviorArgumentAverageRateLimit
type SetRateLimitBehaviorArgumentAverageRateLimit struct {
	Int32 *int32
	String *string
}

// int32AsSetRateLimitBehaviorArgumentAverageRateLimit is a convenience function that returns int32 wrapped in SetRateLimitBehaviorArgumentAverageRateLimit
func Int32AsSetRateLimitBehaviorArgumentAverageRateLimit(v *int32) SetRateLimitBehaviorArgumentAverageRateLimit {
	return SetRateLimitBehaviorArgumentAverageRateLimit{
		Int32: v,
	}
}

// stringAsSetRateLimitBehaviorArgumentAverageRateLimit is a convenience function that returns string wrapped in SetRateLimitBehaviorArgumentAverageRateLimit
func StringAsSetRateLimitBehaviorArgumentAverageRateLimit(v *string) SetRateLimitBehaviorArgumentAverageRateLimit {
	return SetRateLimitBehaviorArgumentAverageRateLimit{
		String: v,
	}
}


// Unmarshal JSON data into one of the pointers in the struct
func (dst *SetRateLimitBehaviorArgumentAverageRateLimit) UnmarshalJSON(data []byte) error {
	var err error
	match := 0
	// try to unmarshal data into Int32
	err = newStrictDecoder(data).Decode(&dst.Int32)
	if err == nil {
		jsonInt32, _ := json.Marshal(dst.Int32)
		if string(jsonInt32) == "{}" { // empty struct
			dst.Int32 = nil
		} else {
			match++
		}
	} else {
		dst.Int32 = nil
	}

	// try to unmarshal data into String
	err = newStrictDecoder(data).Decode(&dst.String)
	if err == nil {
		jsonString, _ := json.Marshal(dst.String)
		if string(jsonString) == "{}" { // empty struct
			dst.String = nil
		} else {
			match++
		}
	} else {
		dst.String = nil
	}

	if match > 1 { // more than 1 match
		// reset to nil
		dst.Int32 = nil
		dst.String = nil

		return fmt.Errorf("data matches more than one schema in oneOf(SetRateLimitBehaviorArgumentAverageRateLimit)")
	} else if match == 1 {
		return nil // exactly one match
	} else { // no match
		return fmt.Errorf("data failed to match schemas in oneOf(SetRateLimitBehaviorArgumentAverageRateLimit)")
	}
}

// Marshal data from the first non-nil pointers in the struct to JSON
func (src SetRateLimitBehaviorArgumentAverageRateLimit) MarshalJSON() ([]byte, error) {
	if src.Int32 != nil {
		return json.Marshal(&src.Int32)
	}

	if src.String != nil {
		return json.Marshal(&src.String)
	}

	return nil, nil // no data in oneOf schemas
}

// Get the actual instance
func (obj *SetRateLimitBehaviorArgumentAverageRateLimit) GetActualInstance() (interface{}) {
	if obj == nil {
		return nil
	}
	if obj.Int32 != nil {
		return obj.Int32
	}

	if obj.String != nil {
		return obj.String
	}

	// all schemas are nil
	return nil
}

type NullableSetRateLimitBehaviorArgumentAverageRateLimit struct {
	value *SetRateLimitBehaviorArgumentAverageRateLimit
	isSet bool
}

func (v NullableSetRateLimitBehaviorArgumentAverageRateLimit) Get() *SetRateLimitBehaviorArgumentAverageRateLimit {
	return v.value
}

func (v *NullableSetRateLimitBehaviorArgumentAverageRateLimit) Set(val *SetRateLimitBehaviorArgumentAverageRateLimit) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableSetRateLimitBehaviorArgumentAverageRateLimit(val *SetRateLimitBehaviorArgumentAverageRateLimit) *NullableSetRateLimitBehaviorArgumentAverageRateLimit {
	return &NullableSetRateLimitBehaviorArgumentAverageRateLimit{value: val, isSet: true}
}

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

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


