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

// Behaviors - struct for Behaviors
type Behaviors struct {
	NullArgumentBehavior *NullArgumentBehavior
	SetCustomResponse *SetCustomResponse
	SetRateLimitBehavior *SetRateLimitBehavior
	SetWAFRuleSetAndWafModeBehavior *SetWAFRuleSetAndWafModeBehavior
	SetWAFRuleSetBehavior *SetWAFRuleSetBehavior
	SimpleArgumentBehavior *SimpleArgumentBehavior
}

// NullArgumentBehaviorAsBehaviors is a convenience function that returns NullArgumentBehavior wrapped in Behaviors
func NullArgumentBehaviorAsBehaviors(v *NullArgumentBehavior) Behaviors {
	return Behaviors{
		NullArgumentBehavior: v,
	}
}

// SetCustomResponseAsBehaviors is a convenience function that returns SetCustomResponse wrapped in Behaviors
func SetCustomResponseAsBehaviors(v *SetCustomResponse) Behaviors {
	return Behaviors{
		SetCustomResponse: v,
	}
}

// SetRateLimitBehaviorAsBehaviors is a convenience function that returns SetRateLimitBehavior wrapped in Behaviors
func SetRateLimitBehaviorAsBehaviors(v *SetRateLimitBehavior) Behaviors {
	return Behaviors{
		SetRateLimitBehavior: v,
	}
}

// SetWAFRuleSetAndWafModeBehaviorAsBehaviors is a convenience function that returns SetWAFRuleSetAndWafModeBehavior wrapped in Behaviors
func SetWAFRuleSetAndWafModeBehaviorAsBehaviors(v *SetWAFRuleSetAndWafModeBehavior) Behaviors {
	return Behaviors{
		SetWAFRuleSetAndWafModeBehavior: v,
	}
}

// SetWAFRuleSetBehaviorAsBehaviors is a convenience function that returns SetWAFRuleSetBehavior wrapped in Behaviors
func SetWAFRuleSetBehaviorAsBehaviors(v *SetWAFRuleSetBehavior) Behaviors {
	return Behaviors{
		SetWAFRuleSetBehavior: v,
	}
}

// SimpleArgumentBehaviorAsBehaviors is a convenience function that returns SimpleArgumentBehavior wrapped in Behaviors
func SimpleArgumentBehaviorAsBehaviors(v *SimpleArgumentBehavior) Behaviors {
	return Behaviors{
		SimpleArgumentBehavior: v,
	}
}


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

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

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

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

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

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

	if match > 1 { // more than 1 match
		// reset to nil
		dst.NullArgumentBehavior = nil
		dst.SetCustomResponse = nil
		dst.SetRateLimitBehavior = nil
		dst.SetWAFRuleSetAndWafModeBehavior = nil
		dst.SetWAFRuleSetBehavior = nil
		dst.SimpleArgumentBehavior = nil

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableBehaviors struct {
	value *Behaviors
	isSet bool
}

func (v NullableBehaviors) Get() *Behaviors {
	return v.value
}

func (v *NullableBehaviors) Set(val *Behaviors) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableBehaviors(val *Behaviors) *NullableBehaviors {
	return &NullableBehaviors{value: val, isSet: true}
}

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

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


