/*
Hindsight HTTP API

HTTP API for Hindsight

API version: 0.4.22
*/

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

package hindsight

import (
	"encoding/json"
	"fmt"
)


// MentalModelTriggerInputTagGroupsInner struct for MentalModelTriggerInputTagGroupsInner
type MentalModelTriggerInputTagGroupsInner struct {
	TagGroupAndInput *TagGroupAndInput
	TagGroupLeaf *TagGroupLeaf
	TagGroupNotInput *TagGroupNotInput
	TagGroupOrInput *TagGroupOrInput
}

// Unmarshal JSON data into any of the pointers in the struct
func (dst *MentalModelTriggerInputTagGroupsInner) UnmarshalJSON(data []byte) error {
	var err error
	// try to unmarshal JSON data into TagGroupAndInput
	err = json.Unmarshal(data, &dst.TagGroupAndInput);
	if err == nil {
		jsonTagGroupAndInput, _ := json.Marshal(dst.TagGroupAndInput)
		if string(jsonTagGroupAndInput) == "{}" { // empty struct
			dst.TagGroupAndInput = nil
		} else {
			return nil // data stored in dst.TagGroupAndInput, return on the first match
		}
	} else {
		dst.TagGroupAndInput = nil
	}

	// try to unmarshal JSON data into TagGroupLeaf
	err = json.Unmarshal(data, &dst.TagGroupLeaf);
	if err == nil {
		jsonTagGroupLeaf, _ := json.Marshal(dst.TagGroupLeaf)
		if string(jsonTagGroupLeaf) == "{}" { // empty struct
			dst.TagGroupLeaf = nil
		} else {
			return nil // data stored in dst.TagGroupLeaf, return on the first match
		}
	} else {
		dst.TagGroupLeaf = nil
	}

	// try to unmarshal JSON data into TagGroupNotInput
	err = json.Unmarshal(data, &dst.TagGroupNotInput);
	if err == nil {
		jsonTagGroupNotInput, _ := json.Marshal(dst.TagGroupNotInput)
		if string(jsonTagGroupNotInput) == "{}" { // empty struct
			dst.TagGroupNotInput = nil
		} else {
			return nil // data stored in dst.TagGroupNotInput, return on the first match
		}
	} else {
		dst.TagGroupNotInput = nil
	}

	// try to unmarshal JSON data into TagGroupOrInput
	err = json.Unmarshal(data, &dst.TagGroupOrInput);
	if err == nil {
		jsonTagGroupOrInput, _ := json.Marshal(dst.TagGroupOrInput)
		if string(jsonTagGroupOrInput) == "{}" { // empty struct
			dst.TagGroupOrInput = nil
		} else {
			return nil // data stored in dst.TagGroupOrInput, return on the first match
		}
	} else {
		dst.TagGroupOrInput = nil
	}

	return fmt.Errorf("data failed to match schemas in anyOf(MentalModelTriggerInputTagGroupsInner)")
}

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

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

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

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

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


type NullableMentalModelTriggerInputTagGroupsInner struct {
	value *MentalModelTriggerInputTagGroupsInner
	isSet bool
}

func (v NullableMentalModelTriggerInputTagGroupsInner) Get() *MentalModelTriggerInputTagGroupsInner {
	return v.value
}

func (v *NullableMentalModelTriggerInputTagGroupsInner) Set(val *MentalModelTriggerInputTagGroupsInner) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableMentalModelTriggerInputTagGroupsInner(val *MentalModelTriggerInputTagGroupsInner) *NullableMentalModelTriggerInputTagGroupsInner {
	return &NullableMentalModelTriggerInputTagGroupsInner{value: val, isSet: true}
}

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

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


