/*
Management API

API version: 3
*/

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

package management

import (
	"encoding/json"
	"fmt"
)

// ScheduleTerminalActionsRequestActionDetails - Information about the action to take.
type ScheduleTerminalActionsRequestActionDetails struct {
	InstallAndroidAppDetails           *InstallAndroidAppDetails
	InstallAndroidCertificateDetails   *InstallAndroidCertificateDetails
	ReleaseUpdateDetails               *ReleaseUpdateDetails
	UninstallAndroidAppDetails         *UninstallAndroidAppDetails
	UninstallAndroidCertificateDetails *UninstallAndroidCertificateDetails
}

// InstallAndroidAppDetailsAsScheduleTerminalActionsRequestActionDetails is a convenience function that returns InstallAndroidAppDetails wrapped in ScheduleTerminalActionsRequestActionDetails
func InstallAndroidAppDetailsAsScheduleTerminalActionsRequestActionDetails(v *InstallAndroidAppDetails) ScheduleTerminalActionsRequestActionDetails {
	return ScheduleTerminalActionsRequestActionDetails{
		InstallAndroidAppDetails: v,
	}
}

// InstallAndroidCertificateDetailsAsScheduleTerminalActionsRequestActionDetails is a convenience function that returns InstallAndroidCertificateDetails wrapped in ScheduleTerminalActionsRequestActionDetails
func InstallAndroidCertificateDetailsAsScheduleTerminalActionsRequestActionDetails(v *InstallAndroidCertificateDetails) ScheduleTerminalActionsRequestActionDetails {
	return ScheduleTerminalActionsRequestActionDetails{
		InstallAndroidCertificateDetails: v,
	}
}

// ReleaseUpdateDetailsAsScheduleTerminalActionsRequestActionDetails is a convenience function that returns ReleaseUpdateDetails wrapped in ScheduleTerminalActionsRequestActionDetails
func ReleaseUpdateDetailsAsScheduleTerminalActionsRequestActionDetails(v *ReleaseUpdateDetails) ScheduleTerminalActionsRequestActionDetails {
	return ScheduleTerminalActionsRequestActionDetails{
		ReleaseUpdateDetails: v,
	}
}

// UninstallAndroidAppDetailsAsScheduleTerminalActionsRequestActionDetails is a convenience function that returns UninstallAndroidAppDetails wrapped in ScheduleTerminalActionsRequestActionDetails
func UninstallAndroidAppDetailsAsScheduleTerminalActionsRequestActionDetails(v *UninstallAndroidAppDetails) ScheduleTerminalActionsRequestActionDetails {
	return ScheduleTerminalActionsRequestActionDetails{
		UninstallAndroidAppDetails: v,
	}
}

// UninstallAndroidCertificateDetailsAsScheduleTerminalActionsRequestActionDetails is a convenience function that returns UninstallAndroidCertificateDetails wrapped in ScheduleTerminalActionsRequestActionDetails
func UninstallAndroidCertificateDetailsAsScheduleTerminalActionsRequestActionDetails(v *UninstallAndroidCertificateDetails) ScheduleTerminalActionsRequestActionDetails {
	return ScheduleTerminalActionsRequestActionDetails{
		UninstallAndroidCertificateDetails: v,
	}
}

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

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

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

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

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

	if match > 1 { // more than 1 match
		// reset to nil
		dst.InstallAndroidAppDetails = nil
		dst.InstallAndroidCertificateDetails = nil
		dst.ReleaseUpdateDetails = nil
		dst.UninstallAndroidAppDetails = nil
		dst.UninstallAndroidCertificateDetails = nil

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

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

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

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

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

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableScheduleTerminalActionsRequestActionDetails struct {
	value *ScheduleTerminalActionsRequestActionDetails
	isSet bool
}

func (v NullableScheduleTerminalActionsRequestActionDetails) Get() *ScheduleTerminalActionsRequestActionDetails {
	return v.value
}

func (v *NullableScheduleTerminalActionsRequestActionDetails) Set(val *ScheduleTerminalActionsRequestActionDetails) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableScheduleTerminalActionsRequestActionDetails(val *ScheduleTerminalActionsRequestActionDetails) *NullableScheduleTerminalActionsRequestActionDetails {
	return &NullableScheduleTerminalActionsRequestActionDetails{value: val, isSet: true}
}

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

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