// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0
/*
Agent Manifest Definition

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

API version: 0.1
*/

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

package manifests

import (
	"encoding/json"
	"fmt"
)

// AgentDeploymentDeploymentOptionsInner - struct for AgentDeploymentDeploymentOptionsInner
type AgentDeploymentDeploymentOptionsInner struct {
	DockerDeployment        *DockerDeployment
	RemoteServiceDeployment *RemoteServiceDeployment
	SourceCodeDeployment    *SourceCodeDeployment
}

// DockerDeploymentAsAgentDeploymentDeploymentOptionsInner is a convenience function that returns DockerDeployment wrapped in AgentDeploymentDeploymentOptionsInner
func DockerDeploymentAsAgentDeploymentDeploymentOptionsInner(v *DockerDeployment) AgentDeploymentDeploymentOptionsInner {
	return AgentDeploymentDeploymentOptionsInner{
		DockerDeployment: v,
	}
}

// RemoteServiceDeploymentAsAgentDeploymentDeploymentOptionsInner is a convenience function that returns RemoteServiceDeployment wrapped in AgentDeploymentDeploymentOptionsInner
func RemoteServiceDeploymentAsAgentDeploymentDeploymentOptionsInner(v *RemoteServiceDeployment) AgentDeploymentDeploymentOptionsInner {
	return AgentDeploymentDeploymentOptionsInner{
		RemoteServiceDeployment: v,
	}
}

// SourceCodeDeploymentAsAgentDeploymentDeploymentOptionsInner is a convenience function that returns SourceCodeDeployment wrapped in AgentDeploymentDeploymentOptionsInner
func SourceCodeDeploymentAsAgentDeploymentDeploymentOptionsInner(v *SourceCodeDeployment) AgentDeploymentDeploymentOptionsInner {
	return AgentDeploymentDeploymentOptionsInner{
		SourceCodeDeployment: v,
	}
}

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

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

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

	if match > 1 { // more than 1 match
		// reset to nil
		dst.DockerDeployment = nil
		dst.RemoteServiceDeployment = nil
		dst.SourceCodeDeployment = nil

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

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableAgentDeploymentDeploymentOptionsInner struct {
	value *AgentDeploymentDeploymentOptionsInner
	isSet bool
}

func (v NullableAgentDeploymentDeploymentOptionsInner) Get() *AgentDeploymentDeploymentOptionsInner {
	return v.value
}

func (v *NullableAgentDeploymentDeploymentOptionsInner) Set(val *AgentDeploymentDeploymentOptionsInner) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableAgentDeploymentDeploymentOptionsInner(val *AgentDeploymentDeploymentOptionsInner) *NullableAgentDeploymentDeploymentOptionsInner {
	return &NullableAgentDeploymentDeploymentOptionsInner{value: val, isSet: true}
}

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

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