package models

import (
	"context"
	"strconv"

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

type ConfigCopyAuthZone struct {

	Comment string `json:"comment,omitempty"`

	ExternalPrimaries []*ConfigExternalPrimary `json:"external_primaries"`

	ExternalSecondaries []*ConfigExternalSecondary `json:"external_secondaries"`

	ID string `json:"id,omitempty"`

	InternalSecondaries []*ConfigInternalSecondary `json:"internal_secondaries"`

	Nsgs []string `json:"nsgs"`

	Recursive bool `json:"recursive,omitempty"`

	SkipOnError bool `json:"skip_on_error,omitempty"`

	TargetView *string `json:"target_view,omitempty"`
}

func (m *ConfigCopyAuthZone) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *ConfigCopyAuthZone) validateExternalPrimaries(formats strfmt.Registry) error {
	if swag.IsZero(m.ExternalPrimaries) { 
		return nil
	}

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) validateExternalSecondaries(formats strfmt.Registry) error {
	if swag.IsZero(m.ExternalSecondaries) { 
		return nil
	}

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) validateInternalSecondaries(formats strfmt.Registry) error {
	if swag.IsZero(m.InternalSecondaries) { 
		return nil
	}

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) validateTargetView(formats strfmt.Registry) error {

	if err := validate.Required("target_view", "body", m.TargetView); err != nil {
		return err
	}

	return nil
}

func (m *ConfigCopyAuthZone) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *ConfigCopyAuthZone) contextValidateExternalPrimaries(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) contextValidateExternalSecondaries(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "id", "body", string(m.ID)); err != nil {
		return err
	}

	return nil
}

func (m *ConfigCopyAuthZone) contextValidateInternalSecondaries(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

func (m *ConfigCopyAuthZone) UnmarshalBinary(b []byte) error {
	var res ConfigCopyAuthZone
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
// 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"
	"github.com/go-openapi/validate"
)

// ConfigCopyAuthZone config copy auth zone
//
// swagger:model configCopyAuthZone
type ConfigCopyAuthZone struct {

	// A comment of the (copied) _dns/auth_zone_ object.
	Comment string `json:"comment,omitempty"`

	// DNS primaries external to BloxOne DDI. Order is not significant.
	ExternalPrimaries []*ConfigExternalPrimary `json:"external_primaries"`

	// DNS secondaries external to BloxOne DDI. Order is not significant.
	ExternalSecondaries []*ConfigExternalSecondary `json:"external_secondaries"`

	// The resource identifier.
	// Read Only: true
	ID string `json:"id,omitempty"`

	// BloxOne DDI hosts acting as internal secondaries. Order is not significant.
	InternalSecondaries []*ConfigInternalSecondary `json:"internal_secondaries"`

	// The resource identifier.
	Nsgs []string `json:"nsgs"`

	// Indicates whether child objects should be copied or not.
	//
	// Defaults to _false_. Reserved for future use.
	Recursive bool `json:"recursive,omitempty"`

	// Indicates whether copying should skip object in case of error and continue with next, or abort copying in case of error.
	//
	// Defaults to _false_.
	SkipOnError bool `json:"skip_on_error,omitempty"`

	// The resource identifier.
	// Required: true
	TargetView *string `json:"target_view,omitempty"`
}

// Validate validates this config copy auth zone
func (m *ConfigCopyAuthZone) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *ConfigCopyAuthZone) validateExternalPrimaries(formats strfmt.Registry) error {
	if swag.IsZero(m.ExternalPrimaries) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) validateExternalSecondaries(formats strfmt.Registry) error {
	if swag.IsZero(m.ExternalSecondaries) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) validateInternalSecondaries(formats strfmt.Registry) error {
	if swag.IsZero(m.InternalSecondaries) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) validateTargetView(formats strfmt.Registry) error {

	if err := validate.Required("target_view", "body", m.TargetView); err != nil {
		return err
	}

	return nil
}

// ContextValidate validate this config copy auth zone based on the context it is used
func (m *ConfigCopyAuthZone) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *ConfigCopyAuthZone) contextValidateExternalPrimaries(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) contextValidateExternalSecondaries(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *ConfigCopyAuthZone) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "id", "body", string(m.ID)); err != nil {
		return err
	}

	return nil
}

func (m *ConfigCopyAuthZone) contextValidateInternalSecondaries(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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