/*
 * Identity
 *
 * Welcome to the Identity HTTP API documentation! You will find documentation for all HTTP APIs here.
 *
 * API version: latest
 */

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

package identityclient

import (
	"encoding/json"
	"fmt"
)

// SubmitLoginFlowBody - struct for SubmitLoginFlowBody
type SubmitLoginFlowBody struct {
	SubmitLoginFlowBodyWithOidc *SubmitLoginFlowBodyWithOidc
	SubmitLoginFlowBodyWithPassword *SubmitLoginFlowBodyWithPassword
	SubmitLoginFlowBodyWithTotp *SubmitLoginFlowBodyWithTotp
}

// SubmitLoginFlowBodyWithOidcAsSubmitLoginFlowBody is a convenience function that returns SubmitLoginFlowBodyWithOidc wrapped in SubmitLoginFlowBody
func SubmitLoginFlowBodyWithOidcAsSubmitLoginFlowBody(v *SubmitLoginFlowBodyWithOidc) SubmitLoginFlowBody {
	return SubmitLoginFlowBody{
		SubmitLoginFlowBodyWithOidc: v,
	}
}

// SubmitLoginFlowBodyWithPasswordAsSubmitLoginFlowBody is a convenience function that returns SubmitLoginFlowBodyWithPassword wrapped in SubmitLoginFlowBody
func SubmitLoginFlowBodyWithPasswordAsSubmitLoginFlowBody(v *SubmitLoginFlowBodyWithPassword) SubmitLoginFlowBody {
	return SubmitLoginFlowBody{
		SubmitLoginFlowBodyWithPassword: v,
	}
}

// SubmitLoginFlowBodyWithTotpAsSubmitLoginFlowBody is a convenience function that returns SubmitLoginFlowBodyWithTotp wrapped in SubmitLoginFlowBody
func SubmitLoginFlowBodyWithTotpAsSubmitLoginFlowBody(v *SubmitLoginFlowBodyWithTotp) SubmitLoginFlowBody {
	return SubmitLoginFlowBody{
		SubmitLoginFlowBodyWithTotp: v,
	}
}


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

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

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

	if match > 1 { // more than 1 match
		// reset to nil
		dst.SubmitLoginFlowBodyWithOidc = nil
		dst.SubmitLoginFlowBodyWithPassword = nil
		dst.SubmitLoginFlowBodyWithTotp = nil

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

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableSubmitLoginFlowBody struct {
	value *SubmitLoginFlowBody
	isSet bool
}

func (v NullableSubmitLoginFlowBody) Get() *SubmitLoginFlowBody {
	return v.value
}

func (v *NullableSubmitLoginFlowBody) Set(val *SubmitLoginFlowBody) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableSubmitLoginFlowBody(val *SubmitLoginFlowBody) *NullableSubmitLoginFlowBody {
	return &NullableSubmitLoginFlowBody{value: val, isSet: true}
}

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

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


