/*
Legal Entity Management API

API version: 3
*/

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

package legalentity

import (
	"encoding/json"
	"fmt"
)

// BankAccountInfoAccountIdentification - Identification of the bank account.
type BankAccountInfoAccountIdentification struct {
	AULocalAccountIdentification      *AULocalAccountIdentification
	CALocalAccountIdentification      *CALocalAccountIdentification
	CZLocalAccountIdentification      *CZLocalAccountIdentification
	DKLocalAccountIdentification      *DKLocalAccountIdentification
	HKLocalAccountIdentification      *HKLocalAccountIdentification
	HULocalAccountIdentification      *HULocalAccountIdentification
	IbanAccountIdentification         *IbanAccountIdentification
	NOLocalAccountIdentification      *NOLocalAccountIdentification
	NZLocalAccountIdentification      *NZLocalAccountIdentification
	NumberAndBicAccountIdentification *NumberAndBicAccountIdentification
	PLLocalAccountIdentification      *PLLocalAccountIdentification
	SELocalAccountIdentification      *SELocalAccountIdentification
	SGLocalAccountIdentification      *SGLocalAccountIdentification
	UKLocalAccountIdentification      *UKLocalAccountIdentification
	USLocalAccountIdentification      *USLocalAccountIdentification
}

// AULocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns AULocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func AULocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *AULocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		AULocalAccountIdentification: v,
	}
}

// CALocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns CALocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func CALocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *CALocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		CALocalAccountIdentification: v,
	}
}

// CZLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns CZLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func CZLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *CZLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		CZLocalAccountIdentification: v,
	}
}

// DKLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns DKLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func DKLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *DKLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		DKLocalAccountIdentification: v,
	}
}

// HKLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns HKLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func HKLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *HKLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		HKLocalAccountIdentification: v,
	}
}

// HULocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns HULocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func HULocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *HULocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		HULocalAccountIdentification: v,
	}
}

// IbanAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns IbanAccountIdentification wrapped in BankAccountInfoAccountIdentification
func IbanAccountIdentificationAsBankAccountInfoAccountIdentification(v *IbanAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		IbanAccountIdentification: v,
	}
}

// NOLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns NOLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func NOLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *NOLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		NOLocalAccountIdentification: v,
	}
}

// NZLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns NZLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func NZLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *NZLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		NZLocalAccountIdentification: v,
	}
}

// NumberAndBicAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns NumberAndBicAccountIdentification wrapped in BankAccountInfoAccountIdentification
func NumberAndBicAccountIdentificationAsBankAccountInfoAccountIdentification(v *NumberAndBicAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		NumberAndBicAccountIdentification: v,
	}
}

// PLLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns PLLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func PLLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *PLLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		PLLocalAccountIdentification: v,
	}
}

// SELocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns SELocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func SELocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *SELocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		SELocalAccountIdentification: v,
	}
}

// SGLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns SGLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func SGLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *SGLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		SGLocalAccountIdentification: v,
	}
}

// UKLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns UKLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func UKLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *UKLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		UKLocalAccountIdentification: v,
	}
}

// USLocalAccountIdentificationAsBankAccountInfoAccountIdentification is a convenience function that returns USLocalAccountIdentification wrapped in BankAccountInfoAccountIdentification
func USLocalAccountIdentificationAsBankAccountInfoAccountIdentification(v *USLocalAccountIdentification) BankAccountInfoAccountIdentification {
	return BankAccountInfoAccountIdentification{
		USLocalAccountIdentification: v,
	}
}

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

	// try to unmarshal data into CALocalAccountIdentification
	err = json.Unmarshal(data, &dst.CALocalAccountIdentification)
	if err == nil {
		jsonCALocalAccountIdentification, _ := json.Marshal(dst.CALocalAccountIdentification)
		if string(jsonCALocalAccountIdentification) == "{}" || !dst.CALocalAccountIdentification.isValidType() { // empty struct
			dst.CALocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.CALocalAccountIdentification = nil
	}

	// try to unmarshal data into CZLocalAccountIdentification
	err = json.Unmarshal(data, &dst.CZLocalAccountIdentification)
	if err == nil {
		jsonCZLocalAccountIdentification, _ := json.Marshal(dst.CZLocalAccountIdentification)
		if string(jsonCZLocalAccountIdentification) == "{}" || !dst.CZLocalAccountIdentification.isValidType() { // empty struct
			dst.CZLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.CZLocalAccountIdentification = nil
	}

	// try to unmarshal data into DKLocalAccountIdentification
	err = json.Unmarshal(data, &dst.DKLocalAccountIdentification)
	if err == nil {
		jsonDKLocalAccountIdentification, _ := json.Marshal(dst.DKLocalAccountIdentification)
		if string(jsonDKLocalAccountIdentification) == "{}" || !dst.DKLocalAccountIdentification.isValidType() { // empty struct
			dst.DKLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.DKLocalAccountIdentification = nil
	}

	// try to unmarshal data into HKLocalAccountIdentification
	err = json.Unmarshal(data, &dst.HKLocalAccountIdentification)
	if err == nil {
		jsonHKLocalAccountIdentification, _ := json.Marshal(dst.HKLocalAccountIdentification)
		if string(jsonHKLocalAccountIdentification) == "{}" || !dst.HKLocalAccountIdentification.isValidType() { // empty struct
			dst.HKLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.HKLocalAccountIdentification = nil
	}

	// try to unmarshal data into HULocalAccountIdentification
	err = json.Unmarshal(data, &dst.HULocalAccountIdentification)
	if err == nil {
		jsonHULocalAccountIdentification, _ := json.Marshal(dst.HULocalAccountIdentification)
		if string(jsonHULocalAccountIdentification) == "{}" || !dst.HULocalAccountIdentification.isValidType() { // empty struct
			dst.HULocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.HULocalAccountIdentification = nil
	}

	// try to unmarshal data into IbanAccountIdentification
	err = json.Unmarshal(data, &dst.IbanAccountIdentification)
	if err == nil {
		jsonIbanAccountIdentification, _ := json.Marshal(dst.IbanAccountIdentification)
		if string(jsonIbanAccountIdentification) == "{}" || !dst.IbanAccountIdentification.isValidType() { // empty struct
			dst.IbanAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.IbanAccountIdentification = nil
	}

	// try to unmarshal data into NOLocalAccountIdentification
	err = json.Unmarshal(data, &dst.NOLocalAccountIdentification)
	if err == nil {
		jsonNOLocalAccountIdentification, _ := json.Marshal(dst.NOLocalAccountIdentification)
		if string(jsonNOLocalAccountIdentification) == "{}" || !dst.NOLocalAccountIdentification.isValidType() { // empty struct
			dst.NOLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.NOLocalAccountIdentification = nil
	}

	// try to unmarshal data into NZLocalAccountIdentification
	err = json.Unmarshal(data, &dst.NZLocalAccountIdentification)
	if err == nil {
		jsonNZLocalAccountIdentification, _ := json.Marshal(dst.NZLocalAccountIdentification)
		if string(jsonNZLocalAccountIdentification) == "{}" || !dst.NZLocalAccountIdentification.isValidType() { // empty struct
			dst.NZLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.NZLocalAccountIdentification = nil
	}

	// try to unmarshal data into NumberAndBicAccountIdentification
	err = json.Unmarshal(data, &dst.NumberAndBicAccountIdentification)
	if err == nil {
		jsonNumberAndBicAccountIdentification, _ := json.Marshal(dst.NumberAndBicAccountIdentification)
		if string(jsonNumberAndBicAccountIdentification) == "{}" || !dst.NumberAndBicAccountIdentification.isValidType() { // empty struct
			dst.NumberAndBicAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.NumberAndBicAccountIdentification = nil
	}

	// try to unmarshal data into PLLocalAccountIdentification
	err = json.Unmarshal(data, &dst.PLLocalAccountIdentification)
	if err == nil {
		jsonPLLocalAccountIdentification, _ := json.Marshal(dst.PLLocalAccountIdentification)
		if string(jsonPLLocalAccountIdentification) == "{}" || !dst.PLLocalAccountIdentification.isValidType() { // empty struct
			dst.PLLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.PLLocalAccountIdentification = nil
	}

	// try to unmarshal data into SELocalAccountIdentification
	err = json.Unmarshal(data, &dst.SELocalAccountIdentification)
	if err == nil {
		jsonSELocalAccountIdentification, _ := json.Marshal(dst.SELocalAccountIdentification)
		if string(jsonSELocalAccountIdentification) == "{}" || !dst.SELocalAccountIdentification.isValidType() { // empty struct
			dst.SELocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.SELocalAccountIdentification = nil
	}

	// try to unmarshal data into SGLocalAccountIdentification
	err = json.Unmarshal(data, &dst.SGLocalAccountIdentification)
	if err == nil {
		jsonSGLocalAccountIdentification, _ := json.Marshal(dst.SGLocalAccountIdentification)
		if string(jsonSGLocalAccountIdentification) == "{}" || !dst.SGLocalAccountIdentification.isValidType() { // empty struct
			dst.SGLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.SGLocalAccountIdentification = nil
	}

	// try to unmarshal data into UKLocalAccountIdentification
	err = json.Unmarshal(data, &dst.UKLocalAccountIdentification)
	if err == nil {
		jsonUKLocalAccountIdentification, _ := json.Marshal(dst.UKLocalAccountIdentification)
		if string(jsonUKLocalAccountIdentification) == "{}" || !dst.UKLocalAccountIdentification.isValidType() { // empty struct
			dst.UKLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.UKLocalAccountIdentification = nil
	}

	// try to unmarshal data into USLocalAccountIdentification
	err = json.Unmarshal(data, &dst.USLocalAccountIdentification)
	if err == nil {
		jsonUSLocalAccountIdentification, _ := json.Marshal(dst.USLocalAccountIdentification)
		if string(jsonUSLocalAccountIdentification) == "{}" || !dst.USLocalAccountIdentification.isValidType() { // empty struct
			dst.USLocalAccountIdentification = nil
		} else {
			match++
		}
	} else {
		dst.USLocalAccountIdentification = nil
	}

	if match > 1 { // more than 1 match
		// reset to nil
		dst.AULocalAccountIdentification = nil
		dst.CALocalAccountIdentification = nil
		dst.CZLocalAccountIdentification = nil
		dst.DKLocalAccountIdentification = nil
		dst.HKLocalAccountIdentification = nil
		dst.HULocalAccountIdentification = nil
		dst.IbanAccountIdentification = nil
		dst.NOLocalAccountIdentification = nil
		dst.NZLocalAccountIdentification = nil
		dst.NumberAndBicAccountIdentification = nil
		dst.PLLocalAccountIdentification = nil
		dst.SELocalAccountIdentification = nil
		dst.SGLocalAccountIdentification = nil
		dst.UKLocalAccountIdentification = nil
		dst.USLocalAccountIdentification = nil

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableBankAccountInfoAccountIdentification struct {
	value *BankAccountInfoAccountIdentification
	isSet bool
}

func (v NullableBankAccountInfoAccountIdentification) Get() *BankAccountInfoAccountIdentification {
	return v.value
}

func (v *NullableBankAccountInfoAccountIdentification) Set(val *BankAccountInfoAccountIdentification) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableBankAccountInfoAccountIdentification(val *BankAccountInfoAccountIdentification) *NullableBankAccountInfoAccountIdentification {
	return &NullableBankAccountInfoAccountIdentification{value: val, isSet: true}
}

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

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