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

// checks if the ModelSchema type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &ModelSchema{}

// ModelSchema struct for ModelSchema
type ModelSchema struct {
	Id      *int32     `json:"id,omitempty"`
	ModelId *int32     `json:"model_id,omitempty"`
	Spec    SchemaSpec `json:"spec"`
}

type _ModelSchema ModelSchema

// NewModelSchema instantiates a new ModelSchema object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewModelSchema(spec SchemaSpec) *ModelSchema {
	this := ModelSchema{}
	this.Spec = spec
	return &this
}

// NewModelSchemaWithDefaults instantiates a new ModelSchema object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewModelSchemaWithDefaults() *ModelSchema {
	this := ModelSchema{}
	return &this
}

// GetId returns the Id field value if set, zero value otherwise.
func (o *ModelSchema) GetId() int32 {
	if o == nil || IsNil(o.Id) {
		var ret int32
		return ret
	}
	return *o.Id
}

// GetIdOk returns a tuple with the Id field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ModelSchema) GetIdOk() (*int32, bool) {
	if o == nil || IsNil(o.Id) {
		return nil, false
	}
	return o.Id, true
}

// HasId returns a boolean if a field has been set.
func (o *ModelSchema) HasId() bool {
	if o != nil && !IsNil(o.Id) {
		return true
	}

	return false
}

// SetId gets a reference to the given int32 and assigns it to the Id field.
func (o *ModelSchema) SetId(v int32) {
	o.Id = &v
}

// GetModelId returns the ModelId field value if set, zero value otherwise.
func (o *ModelSchema) GetModelId() int32 {
	if o == nil || IsNil(o.ModelId) {
		var ret int32
		return ret
	}
	return *o.ModelId
}

// GetModelIdOk returns a tuple with the ModelId field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ModelSchema) GetModelIdOk() (*int32, bool) {
	if o == nil || IsNil(o.ModelId) {
		return nil, false
	}
	return o.ModelId, true
}

// HasModelId returns a boolean if a field has been set.
func (o *ModelSchema) HasModelId() bool {
	if o != nil && !IsNil(o.ModelId) {
		return true
	}

	return false
}

// SetModelId gets a reference to the given int32 and assigns it to the ModelId field.
func (o *ModelSchema) SetModelId(v int32) {
	o.ModelId = &v
}

// GetSpec returns the Spec field value
func (o *ModelSchema) GetSpec() SchemaSpec {
	if o == nil {
		var ret SchemaSpec
		return ret
	}

	return o.Spec
}

// GetSpecOk returns a tuple with the Spec field value
// and a boolean to check if the value has been set.
func (o *ModelSchema) GetSpecOk() (*SchemaSpec, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Spec, true
}

// SetSpec sets field value
func (o *ModelSchema) SetSpec(v SchemaSpec) {
	o.Spec = v
}

func (o ModelSchema) MarshalJSON() ([]byte, error) {
	toSerialize, err := o.ToMap()
	if err != nil {
		return []byte{}, err
	}
	return json.Marshal(toSerialize)
}

func (o ModelSchema) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	if !IsNil(o.Id) {
		toSerialize["id"] = o.Id
	}
	if !IsNil(o.ModelId) {
		toSerialize["model_id"] = o.ModelId
	}
	toSerialize["spec"] = o.Spec
	return toSerialize, nil
}

func (o *ModelSchema) UnmarshalJSON(bytes []byte) (err error) {
	// This validates that all required properties are included in the JSON object
	// by unmarshalling the object into a generic map with string keys and checking
	// that every required field exists as a key in the generic map.
	requiredProperties := []string{
		"spec",
	}

	allProperties := make(map[string]interface{})

	err = json.Unmarshal(bytes, &allProperties)

	if err != nil {
		return err
	}

	for _, requiredProperty := range requiredProperties {
		if _, exists := allProperties[requiredProperty]; !exists {
			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

	varModelSchema := _ModelSchema{}

	err = json.Unmarshal(bytes, &varModelSchema)

	if err != nil {
		return err
	}

	*o = ModelSchema(varModelSchema)

	return err
}

type NullableModelSchema struct {
	value *ModelSchema
	isSet bool
}

func (v NullableModelSchema) Get() *ModelSchema {
	return v.value
}

func (v *NullableModelSchema) Set(val *ModelSchema) {
	v.value = val
	v.isSet = true
}

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

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

func NewNullableModelSchema(val *ModelSchema) *NullableModelSchema {
	return &NullableModelSchema{value: val, isSet: true}
}

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

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