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

// AlertManagersResult AlertManagersResult contains the result from querying the alertmanagers endpoint.
//
// swagger:model AlertManagersResult
type AlertManagersResult struct {

	// active alert managers
	ActiveAlertManagers []*AlertManager `json:"activeAlertManagers"`

	// dropped alert managers
	DroppedAlertManagers []*AlertManager `json:"droppedAlertManagers"`
}

// Validate validates this alert managers result
func (m *AlertManagersResult) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *AlertManagersResult) validateActiveAlertManagers(formats strfmt.Registry) error {
	if swag.IsZero(m.ActiveAlertManagers) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *AlertManagersResult) validateDroppedAlertManagers(formats strfmt.Registry) error {
	if swag.IsZero(m.DroppedAlertManagers) { // not required
		return nil
	}

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

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

	}

	return nil
}

// ContextValidate validate this alert managers result based on the context it is used
func (m *AlertManagersResult) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *AlertManagersResult) contextValidateActiveAlertManagers(ctx context.Context, formats strfmt.Registry) error {

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

		if m.ActiveAlertManagers[i] != nil {

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

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

	}

	return nil
}

func (m *AlertManagersResult) contextValidateDroppedAlertManagers(ctx context.Context, formats strfmt.Registry) error {

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

		if m.DroppedAlertManagers[i] != nil {

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

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

	}

	return nil
}

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

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