// 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"
)

// SourceCodeDeploymentFrameworkConfig - struct for SourceCodeDeploymentFrameworkConfig
type SourceCodeDeploymentFrameworkConfig struct {
	LangGraphConfig  *LangGraphConfig
	LlamaIndexConfig *LlamaIndexConfig
}

// LangGraphConfigAsSourceCodeDeploymentFrameworkConfig is a convenience function that returns LangGraphConfig wrapped in SourceCodeDeploymentFrameworkConfig
func LangGraphConfigAsSourceCodeDeploymentFrameworkConfig(v *LangGraphConfig) SourceCodeDeploymentFrameworkConfig {
	return SourceCodeDeploymentFrameworkConfig{
		LangGraphConfig: v,
	}
}

// LlamaIndexConfigAsSourceCodeDeploymentFrameworkConfig is a convenience function that returns LlamaIndexConfig wrapped in SourceCodeDeploymentFrameworkConfig
func LlamaIndexConfigAsSourceCodeDeploymentFrameworkConfig(v *LlamaIndexConfig) SourceCodeDeploymentFrameworkConfig {
	return SourceCodeDeploymentFrameworkConfig{
		LlamaIndexConfig: v,
	}
}

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

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

	if match > 1 { // more than 1 match
		// reset to nil
		dst.LangGraphConfig = nil
		dst.LlamaIndexConfig = nil

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableSourceCodeDeploymentFrameworkConfig struct {
	value *SourceCodeDeploymentFrameworkConfig
	isSet bool
}

func (v NullableSourceCodeDeploymentFrameworkConfig) Get() *SourceCodeDeploymentFrameworkConfig {
	return v.value
}

func (v *NullableSourceCodeDeploymentFrameworkConfig) Set(val *SourceCodeDeploymentFrameworkConfig) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableSourceCodeDeploymentFrameworkConfig(val *SourceCodeDeploymentFrameworkConfig) *NullableSourceCodeDeploymentFrameworkConfig {
	return &NullableSourceCodeDeploymentFrameworkConfig{value: val, isSet: true}
}

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

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