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

// VPNConnectionCreateResponse v p n connection create response
//
// swagger:model VPNConnectionCreateResponse
type VPNConnectionCreateResponse struct {
	VPNConnection

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

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

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

	return nil
}

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

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

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

	jsonDataPropsVPNConnectionCreateResponse, errVPNConnectionCreateResponse := swag.WriteJSON(propsVPNConnectionCreateResponse)
	if errVPNConnectionCreateResponse != nil {
		return nil, errVPNConnectionCreateResponse
	}
	_parts = append(_parts, jsonDataPropsVPNConnectionCreateResponse)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this v p n connection create response
func (m *VPNConnectionCreateResponse) Validate(formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with VPNConnection
	if err := m.VPNConnection.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 *VPNConnectionCreateResponse) 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 v p n connection create response based on the context it is used
func (m *VPNConnectionCreateResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with VPNConnection
	if err := m.VPNConnection.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 *VPNConnectionCreateResponse) 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 *VPNConnectionCreateResponse) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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