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

// SentryBootstrapAgentTemplateSpec sentry bootstrap agent template spec
//
// swagger:model sentryBootstrapAgentTemplateSpec
type SentryBootstrapAgentTemplateSpec struct {

	// auto approve
	AutoApprove bool `json:"autoApprove,omitempty"`

	// auto register
	AutoRegister bool `json:"autoRegister,omitempty"`

	// hosts
	Hosts []*SentryBootstrapTemplateHost `json:"hosts"`

	// ignore multiple register
	IgnoreMultipleRegister bool `json:"ignoreMultipleRegister,omitempty"`

	// in cluster template
	InClusterTemplate string `json:"inClusterTemplate,omitempty"`

	// infra ref
	InfraRef string `json:"infraRef,omitempty"`

	// out of cluster template
	OutOfClusterTemplate string `json:"outOfClusterTemplate,omitempty"`

	// template type
	TemplateType *SentryBootstrapAgentTemplateType `json:"templateType,omitempty"`

	// token
	Token string `json:"token,omitempty"`
}

// Validate validates this sentry bootstrap agent template spec
func (m *SentryBootstrapAgentTemplateSpec) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SentryBootstrapAgentTemplateSpec) validateHosts(formats strfmt.Registry) error {
	if swag.IsZero(m.Hosts) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *SentryBootstrapAgentTemplateSpec) validateTemplateType(formats strfmt.Registry) error {
	if swag.IsZero(m.TemplateType) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this sentry bootstrap agent template spec based on the context it is used
func (m *SentryBootstrapAgentTemplateSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SentryBootstrapAgentTemplateSpec) contextValidateHosts(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *SentryBootstrapAgentTemplateSpec) contextValidateTemplateType(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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