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

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

// VPNConnections v p n connections
//
// swagger:model VPNConnections
type VPNConnections struct {

	// an array of VPN Connections
	// Example: [{"deadPeerDetection":{"action":"restart","interval":10,"threshold":5},"id":"123e4567-e89b-12d3-a456-42661475","ikePolicy":{"id":"7654e321-e89b-12d3-a456-4566447","name":"IKE Policy 3"},"ipSecPolicy":{"id":"456f7890-e89b-12d3-a456-4569934","name":"IPSec Policy 2"},"localGatewayAddress":"192.168.1.1","mode":"route","name":"VPN Connection 2","peerGatewayAddress":"192.168.44.1","peerSubnets":["128.169.1.0/24","128.168.1.0/27"],"status":"Active","vpnGatewayAddress":"192.168.24.1"}]
	VpnConnections []*VPNConnection `json:"vpnConnections"`
}

// Validate validates this v p n connections
func (m *VPNConnections) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *VPNConnections) validateVpnConnections(formats strfmt.Registry) error {
	if swag.IsZero(m.VpnConnections) { // not required
		return nil
	}

	for i := 0; i < len(m.VpnConnections); i++ {
		if swag.IsZero(m.VpnConnections[i]) { // not required
			continue
		}

		if m.VpnConnections[i] != nil {
			if err := m.VpnConnections[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("vpnConnections" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("vpnConnections" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this v p n connections based on the context it is used
func (m *VPNConnections) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *VPNConnections) contextValidateVpnConnections(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.VpnConnections); i++ {

		if m.VpnConnections[i] != nil {

			if swag.IsZero(m.VpnConnections[i]) { // not required
				return nil
			}

			if err := m.VpnConnections[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("vpnConnections" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("vpnConnections" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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