/*
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"
)

// BehaviorsArgument - struct for BehaviorsArgument
type BehaviorsArgument struct {
	GenericBehaviorDetails *GenericBehaviorDetails
	SetRateLimitDetails *SetRateLimitDetails
	SetWAFRuleSetDetails *SetWAFRuleSetDetails
}

// GenericBehaviorDetailsAsBehaviorsArgument is a convenience function that returns GenericBehaviorDetails wrapped in BehaviorsArgument
func GenericBehaviorDetailsAsBehaviorsArgument(v *GenericBehaviorDetails) BehaviorsArgument {
	return BehaviorsArgument{
		GenericBehaviorDetails: v,
	}
}

// SetRateLimitDetailsAsBehaviorsArgument is a convenience function that returns SetRateLimitDetails wrapped in BehaviorsArgument
func SetRateLimitDetailsAsBehaviorsArgument(v *SetRateLimitDetails) BehaviorsArgument {
	return BehaviorsArgument{
		SetRateLimitDetails: v,
	}
}

// SetWAFRuleSetDetailsAsBehaviorsArgument is a convenience function that returns SetWAFRuleSetDetails wrapped in BehaviorsArgument
func SetWAFRuleSetDetailsAsBehaviorsArgument(v *SetWAFRuleSetDetails) BehaviorsArgument {
	return BehaviorsArgument{
		SetWAFRuleSetDetails: v,
	}
}


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

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

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

	if match > 1 { // more than 1 match
		// reset to nil
		dst.GenericBehaviorDetails = nil
		dst.SetRateLimitDetails = nil
		dst.SetWAFRuleSetDetails = nil

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

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableBehaviorsArgument struct {
	value *BehaviorsArgument
	isSet bool
}

func (v NullableBehaviorsArgument) Get() *BehaviorsArgument {
	return v.value
}

func (v *NullableBehaviorsArgument) Set(val *BehaviorsArgument) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableBehaviorsArgument(val *BehaviorsArgument) *NullableBehaviorsArgument {
	return &NullableBehaviorsArgument{value: val, isSet: true}
}

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

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


