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

// SaveMode the model 'SaveMode'
type SaveMode int32

// List of SaveMode
const (
	SAVEMODE__0 SaveMode = 0
	SAVEMODE__1 SaveMode = 1
	SAVEMODE__2 SaveMode = 2
	SAVEMODE__3 SaveMode = 3
	SAVEMODE__4 SaveMode = 4
)

// All allowed values of SaveMode enum
var AllowedSaveModeEnumValues = []SaveMode{
	0,
	1,
	2,
	3,
	4,
}

func (v *SaveMode) UnmarshalJSON(src []byte) error {
	var value int32
	err := json.Unmarshal(src, &value)
	if err != nil {
		return err
	}
	enumTypeValue := SaveMode(value)
	for _, existing := range AllowedSaveModeEnumValues {
		if existing == enumTypeValue {
			*v = enumTypeValue
			return nil
		}
	}

	return fmt.Errorf("%+v is not a valid SaveMode", value)
}

// NewSaveModeFromValue returns a pointer to a valid SaveMode
// for the value passed as argument, or an error if the value passed is not allowed by the enum
func NewSaveModeFromValue(v int32) (*SaveMode, error) {
	ev := SaveMode(v)
	if ev.IsValid() {
		return &ev, nil
	} else {
		return nil, fmt.Errorf("invalid value '%v' for SaveMode: valid values are %v", v, AllowedSaveModeEnumValues)
	}
}

// IsValid return true if the value is valid for the enum, false otherwise
func (v SaveMode) IsValid() bool {
	for _, existing := range AllowedSaveModeEnumValues {
		if existing == v {
			return true
		}
	}
	return false
}

// Ptr returns reference to SaveMode value
func (v SaveMode) Ptr() *SaveMode {
	return &v
}

type NullableSaveMode struct {
	value *SaveMode
	isSet bool
}

func (v NullableSaveMode) Get() *SaveMode {
	return v.value
}

func (v *NullableSaveMode) Set(val *SaveMode) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableSaveMode(val *SaveMode) *NullableSaveMode {
	return &NullableSaveMode{value: val, isSet: true}
}

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

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