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

package models

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

import (
	"context"

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

// CloudConnectionCreateResponse cloud connection create response
//
// swagger:model CloudConnectionCreateResponse
type CloudConnectionCreateResponse struct {
	CloudConnection

	// job ref
	JobRef *JobReference `json:"jobRef,omitempty"`
}

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

	// now for regular properties
	var propsCloudConnectionCreateResponse struct {
		JobRef *JobReference `json:"jobRef,omitempty"`
	}
	if err := swag.ReadJSON(raw, &propsCloudConnectionCreateResponse); err != nil {
		return err
	}
	m.JobRef = propsCloudConnectionCreateResponse.JobRef

	return nil
}

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

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

	// now for regular properties
	var propsCloudConnectionCreateResponse struct {
		JobRef *JobReference `json:"jobRef,omitempty"`
	}
	propsCloudConnectionCreateResponse.JobRef = m.JobRef

	jsonDataPropsCloudConnectionCreateResponse, errCloudConnectionCreateResponse := swag.WriteJSON(propsCloudConnectionCreateResponse)
	if errCloudConnectionCreateResponse != nil {
		return nil, errCloudConnectionCreateResponse
	}
	_parts = append(_parts, jsonDataPropsCloudConnectionCreateResponse)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this cloud connection create response
func (m *CloudConnectionCreateResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CloudConnectionCreateResponse) validateJobRef(formats strfmt.Registry) error {
	if swag.IsZero(m.JobRef) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this cloud connection create response based on the context it is used
func (m *CloudConnectionCreateResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CloudConnectionCreateResponse) contextValidateJobRef(ctx context.Context, formats strfmt.Registry) error {

	if m.JobRef != nil {

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

		if err := m.JobRef.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("jobRef")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("jobRef")
			}
			return err
		}
	}

	return nil
}

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

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