// Code generated by go-swagger; DO NOT EDIT.

package types

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"github.com/go-openapi/errors"
	strfmt "github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// UpdateConfig UpdateConfig holds the mutable attributes of a Container. Those attributes can be updated at runtime.
// swagger:model UpdateConfig
type UpdateConfig struct {
	Resources

	// update disk quota for container
	DiskQuota map[string]string `json:"DiskQuota,omitempty"`

	// A list of environment variables to set inside the container in the form `["VAR=value", ...]`.
	// A variable like "A=" means updating env A in container to be empty value.
	// A variable without `=` is removed from the environment, rather than to have an empty value.
	//
	Env []string `json:"Env"`

	// List of labels set to container.
	Label []string `json:"Label"`

	// restart policy
	RestartPolicy *RestartPolicy `json:"RestartPolicy,omitempty"`

	// update specAnnotation for container
	SpecAnnotation map[string]string `json:"SpecAnnotation,omitempty"`
}

// UnmarshalJSON unmarshals this object from a JSON structure
func (m *UpdateConfig) UnmarshalJSON(raw []byte) error {
	// AO0
	var aO0 Resources
	if err := swag.ReadJSON(raw, &aO0); err != nil {
		return err
	}
	m.Resources = aO0

	// AO1
	var dataAO1 struct {
		DiskQuota map[string]string `json:"DiskQuota,omitempty"`

		Env []string `json:"Env"`

		Label []string `json:"Label"`

		RestartPolicy *RestartPolicy `json:"RestartPolicy,omitempty"`

		SpecAnnotation map[string]string `json:"SpecAnnotation,omitempty"`
	}
	if err := swag.ReadJSON(raw, &dataAO1); err != nil {
		return err
	}

	m.DiskQuota = dataAO1.DiskQuota

	m.Env = dataAO1.Env

	m.Label = dataAO1.Label

	m.RestartPolicy = dataAO1.RestartPolicy

	m.SpecAnnotation = dataAO1.SpecAnnotation

	return nil
}

// MarshalJSON marshals this object to a JSON structure
func (m UpdateConfig) MarshalJSON() ([]byte, error) {
	_parts := make([][]byte, 0, 2)

	aO0, err := swag.WriteJSON(m.Resources)
	if err != nil {
		return nil, err
	}
	_parts = append(_parts, aO0)

	var dataAO1 struct {
		DiskQuota map[string]string `json:"DiskQuota,omitempty"`

		Env []string `json:"Env"`

		Label []string `json:"Label"`

		RestartPolicy *RestartPolicy `json:"RestartPolicy,omitempty"`

		SpecAnnotation map[string]string `json:"SpecAnnotation,omitempty"`
	}

	dataAO1.DiskQuota = m.DiskQuota

	dataAO1.Env = m.Env

	dataAO1.Label = m.Label

	dataAO1.RestartPolicy = m.RestartPolicy

	dataAO1.SpecAnnotation = m.SpecAnnotation

	jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
	if errAO1 != nil {
		return nil, errAO1
	}
	_parts = append(_parts, jsonDataAO1)

	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this update config
func (m *UpdateConfig) Validate(formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with Resources
	if err := m.Resources.Validate(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateRestartPolicy(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *UpdateConfig) validateRestartPolicy(formats strfmt.Registry) error {

	if swag.IsZero(m.RestartPolicy) { // not required
		return nil
	}

	if m.RestartPolicy != nil {
		if err := m.RestartPolicy.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("RestartPolicy")
			}
			return err
		}
	}

	return nil
}

// MarshalBinary interface implementation
func (m *UpdateConfig) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *UpdateConfig) UnmarshalBinary(b []byte) error {
	var res UpdateConfig
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
