/*
Edge Functions Instances 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 edgefunctionsinstance_edgefirewall

import (
	"encoding/json"
	"fmt"
	"gopkg.in/validator.v2"
)

// EdgeFunctionsInstanceJsonArgs - struct for EdgeFunctionsInstanceJsonArgs
type EdgeFunctionsInstanceJsonArgs struct {
	ArrayOfMapmapOfStringAny *[]map[string]interface{}
	MapmapOfStringAny *map[string]interface{}
}

// []map[string]interface{}AsEdgeFunctionsInstanceJsonArgs is a convenience function that returns []map[string]interface{} wrapped in EdgeFunctionsInstanceJsonArgs
func ArrayOfMapmapOfStringAnyAsEdgeFunctionsInstanceJsonArgs(v *[]map[string]interface{}) EdgeFunctionsInstanceJsonArgs {
	return EdgeFunctionsInstanceJsonArgs{
		ArrayOfMapmapOfStringAny: v,
	}
}

// map[string]interface{}AsEdgeFunctionsInstanceJsonArgs is a convenience function that returns map[string]interface{} wrapped in EdgeFunctionsInstanceJsonArgs
func MapmapOfStringAnyAsEdgeFunctionsInstanceJsonArgs(v *map[string]interface{}) EdgeFunctionsInstanceJsonArgs {
	return EdgeFunctionsInstanceJsonArgs{
		MapmapOfStringAny: v,
	}
}


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

	// try to unmarshal data into MapmapOfStringAny
	err = newStrictDecoder(data).Decode(&dst.MapmapOfStringAny)
	if err == nil {
		jsonMapmapOfStringAny, _ := json.Marshal(dst.MapmapOfStringAny)
		if string(jsonMapmapOfStringAny) == "{}" { // empty struct
			dst.MapmapOfStringAny = nil
		} else {
			if err = validator.Validate(dst.MapmapOfStringAny); err != nil {
				dst.MapmapOfStringAny = nil
			} else {
				match++
			}
		}
	} else {
		dst.MapmapOfStringAny = nil
	}

	if match > 1 { // more than 1 match
		// reset to nil
		dst.ArrayOfMapmapOfStringAny = nil
		dst.MapmapOfStringAny = nil

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

// Get the actual instance value
func (obj EdgeFunctionsInstanceJsonArgs) GetActualInstanceValue() (interface{}) {
	if obj.ArrayOfMapmapOfStringAny != nil {
		return *obj.ArrayOfMapmapOfStringAny
	}

	if obj.MapmapOfStringAny != nil {
		return *obj.MapmapOfStringAny
	}

	// all schemas are nil
	return nil
}

type NullableEdgeFunctionsInstanceJsonArgs struct {
	value *EdgeFunctionsInstanceJsonArgs
	isSet bool
}

func (v NullableEdgeFunctionsInstanceJsonArgs) Get() *EdgeFunctionsInstanceJsonArgs {
	return v.value
}

func (v *NullableEdgeFunctionsInstanceJsonArgs) Set(val *EdgeFunctionsInstanceJsonArgs) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableEdgeFunctionsInstanceJsonArgs(val *EdgeFunctionsInstanceJsonArgs) *NullableEdgeFunctionsInstanceJsonArgs {
	return &NullableEdgeFunctionsInstanceJsonArgs{value: val, isSet: true}
}

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

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


