/*
Edge Application 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 edgeapplications

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

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

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

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


// Unmarshal JSON data into one of the pointers in the struct
func (dst *ApplicationCreateInstanceRequestArgs) 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(ApplicationCreateInstanceRequestArgs)")
	} else if match == 1 {
		return nil // exactly one match
	} else { // no match
		return fmt.Errorf("data failed to match schemas in oneOf(ApplicationCreateInstanceRequestArgs)")
	}
}

// Marshal data from the first non-nil pointers in the struct to JSON
func (src ApplicationCreateInstanceRequestArgs) 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 *ApplicationCreateInstanceRequestArgs) 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 ApplicationCreateInstanceRequestArgs) GetActualInstanceValue() (interface{}) {
	if obj.ArrayOfMapmapOfStringAny != nil {
		return *obj.ArrayOfMapmapOfStringAny
	}

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

	// all schemas are nil
	return nil
}

type NullableApplicationCreateInstanceRequestArgs struct {
	value *ApplicationCreateInstanceRequestArgs
	isSet bool
}

func (v NullableApplicationCreateInstanceRequestArgs) Get() *ApplicationCreateInstanceRequestArgs {
	return v.value
}

func (v *NullableApplicationCreateInstanceRequestArgs) Set(val *ApplicationCreateInstanceRequestArgs) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableApplicationCreateInstanceRequestArgs(val *ApplicationCreateInstanceRequestArgs) *NullableApplicationCreateInstanceRequestArgs {
	return &NullableApplicationCreateInstanceRequestArgs{value: val, isSet: true}
}

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

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


