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

// ContainerCreateConfig ContainerCreateConfig is used for API "POST /containers/create".
// It wraps all kinds of config used in container creation.
// It can be used to encode client params in client and unmarshal request body in daemon side.
//
// swagger:model ContainerCreateConfig
type ContainerCreateConfig struct {
	ContainerConfig

	// host config
	HostConfig *HostConfig `json:"HostConfig,omitempty"`

	// networking config
	NetworkingConfig *NetworkingConfig `json:"NetworkingConfig,omitempty"`
}

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

	// AO1
	var dataAO1 struct {
		HostConfig *HostConfig `json:"HostConfig,omitempty"`

		NetworkingConfig *NetworkingConfig `json:"NetworkingConfig,omitempty"`
	}
	if err := swag.ReadJSON(raw, &dataAO1); err != nil {
		return err
	}

	m.HostConfig = dataAO1.HostConfig

	m.NetworkingConfig = dataAO1.NetworkingConfig

	return nil
}

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

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

	var dataAO1 struct {
		HostConfig *HostConfig `json:"HostConfig,omitempty"`

		NetworkingConfig *NetworkingConfig `json:"NetworkingConfig,omitempty"`
	}

	dataAO1.HostConfig = m.HostConfig

	dataAO1.NetworkingConfig = m.NetworkingConfig

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

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

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

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

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

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

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

func (m *ContainerCreateConfig) validateHostConfig(formats strfmt.Registry) error {

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

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

	return nil
}

func (m *ContainerCreateConfig) validateNetworkingConfig(formats strfmt.Registry) error {

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

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

	return nil
}

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

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