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

// Secrets20231128MongoDBAtlasSecretDetails secrets 20231128 mongo d b atlas secret details
//
// swagger:model secrets_20231128MongoDBAtlasSecretDetails
type Secrets20231128MongoDBAtlasSecretDetails struct {

	// mongodb group id
	MongodbGroupID string `json:"mongodb_group_id,omitempty"`

	// mongodb roles
	MongodbRoles []*Secrets20231128MongoDBRole `json:"mongodb_roles"`

	// mongodb scopes
	MongodbScopes []*Secrets20231128MongoDBScope `json:"mongodb_scopes"`
}

// Validate validates this secrets 20231128 mongo d b atlas secret details
func (m *Secrets20231128MongoDBAtlasSecretDetails) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *Secrets20231128MongoDBAtlasSecretDetails) validateMongodbRoles(formats strfmt.Registry) error {
	if swag.IsZero(m.MongodbRoles) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *Secrets20231128MongoDBAtlasSecretDetails) validateMongodbScopes(formats strfmt.Registry) error {
	if swag.IsZero(m.MongodbScopes) { // not required
		return nil
	}

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

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

	}

	return nil
}

// ContextValidate validate this secrets 20231128 mongo d b atlas secret details based on the context it is used
func (m *Secrets20231128MongoDBAtlasSecretDetails) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *Secrets20231128MongoDBAtlasSecretDetails) contextValidateMongodbRoles(ctx context.Context, formats strfmt.Registry) error {

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

		if m.MongodbRoles[i] != nil {

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

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

	}

	return nil
}

func (m *Secrets20231128MongoDBAtlasSecretDetails) contextValidateMongodbScopes(ctx context.Context, formats strfmt.Registry) error {

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

		if m.MongodbScopes[i] != nil {

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

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

	}

	return nil
}

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

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