/*
Merlin

API Guide for accessing Merlin's model management, deployment, and serving functionalities

API version: 0.14.0
*/

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

package client

import (
	"encoding/json"
	"fmt"
)

// ModelPredictionOutput - struct for ModelPredictionOutput
type ModelPredictionOutput struct {
	BinaryClassificationOutput *BinaryClassificationOutput
	RankingOutput              *RankingOutput
	RegressionOutput           *RegressionOutput
}

// BinaryClassificationOutputAsModelPredictionOutput is a convenience function that returns BinaryClassificationOutput wrapped in ModelPredictionOutput
func BinaryClassificationOutputAsModelPredictionOutput(v *BinaryClassificationOutput) ModelPredictionOutput {
	return ModelPredictionOutput{
		BinaryClassificationOutput: v,
	}
}

// RankingOutputAsModelPredictionOutput is a convenience function that returns RankingOutput wrapped in ModelPredictionOutput
func RankingOutputAsModelPredictionOutput(v *RankingOutput) ModelPredictionOutput {
	return ModelPredictionOutput{
		RankingOutput: v,
	}
}

// RegressionOutputAsModelPredictionOutput is a convenience function that returns RegressionOutput wrapped in ModelPredictionOutput
func RegressionOutputAsModelPredictionOutput(v *RegressionOutput) ModelPredictionOutput {
	return ModelPredictionOutput{
		RegressionOutput: v,
	}
}

// Unmarshal JSON data into one of the pointers in the struct
func (dst *ModelPredictionOutput) UnmarshalJSON(data []byte) error {
	var err error
	// use discriminator value to speed up the lookup
	var jsonDict map[string]interface{}
	err = newStrictDecoder(data).Decode(&jsonDict)
	if err != nil {
		return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup")
	}

	// check if the discriminator value is 'BinaryClassificationOutput'
	if jsonDict["output_class"] == "BinaryClassificationOutput" {
		// try to unmarshal JSON data into BinaryClassificationOutput
		err = json.Unmarshal(data, &dst.BinaryClassificationOutput)
		if err == nil {
			return nil // data stored in dst.BinaryClassificationOutput, return on the first match
		} else {
			dst.BinaryClassificationOutput = nil
			return fmt.Errorf("failed to unmarshal ModelPredictionOutput as BinaryClassificationOutput: %s", err.Error())
		}
	}

	// check if the discriminator value is 'RankingOutput'
	if jsonDict["output_class"] == "RankingOutput" {
		// try to unmarshal JSON data into RankingOutput
		err = json.Unmarshal(data, &dst.RankingOutput)
		if err == nil {
			return nil // data stored in dst.RankingOutput, return on the first match
		} else {
			dst.RankingOutput = nil
			return fmt.Errorf("failed to unmarshal ModelPredictionOutput as RankingOutput: %s", err.Error())
		}
	}

	// check if the discriminator value is 'RegressionOutput'
	if jsonDict["output_class"] == "RegressionOutput" {
		// try to unmarshal JSON data into RegressionOutput
		err = json.Unmarshal(data, &dst.RegressionOutput)
		if err == nil {
			return nil // data stored in dst.RegressionOutput, return on the first match
		} else {
			dst.RegressionOutput = nil
			return fmt.Errorf("failed to unmarshal ModelPredictionOutput as RegressionOutput: %s", err.Error())
		}
	}

	return nil
}

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

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

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

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

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

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

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

	// all schemas are nil
	return nil
}

type NullableModelPredictionOutput struct {
	value *ModelPredictionOutput
	isSet bool
}

func (v NullableModelPredictionOutput) Get() *ModelPredictionOutput {
	return v.value
}

func (v *NullableModelPredictionOutput) Set(val *ModelPredictionOutput) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableModelPredictionOutput(val *ModelPredictionOutput) *NullableModelPredictionOutput {
	return &NullableModelPredictionOutput{value: val, isSet: true}
}

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

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