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

// SecretServiceBulkCreateAppKVSecretsBody secret service bulk create app k v secrets body
//
// swagger:model SecretServiceBulkCreateAppKVSecretsBody
type SecretServiceBulkCreateAppKVSecretsBody struct {

	// conflicts
	Conflicts *BulkCreateAppKVSecretsRequestNameConflictPolicy `json:"conflicts,omitempty"`

	// secrets
	Secrets []*BulkCreateAppKVSecretsRequestKeyValue `json:"secrets"`
}

// Validate validates this secret service bulk create app k v secrets body
func (m *SecretServiceBulkCreateAppKVSecretsBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SecretServiceBulkCreateAppKVSecretsBody) validateConflicts(formats strfmt.Registry) error {
	if swag.IsZero(m.Conflicts) { // not required
		return nil
	}

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

	return nil
}

func (m *SecretServiceBulkCreateAppKVSecretsBody) validateSecrets(formats strfmt.Registry) error {
	if swag.IsZero(m.Secrets) { // not required
		return nil
	}

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

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

	}

	return nil
}

// ContextValidate validate this secret service bulk create app k v secrets body based on the context it is used
func (m *SecretServiceBulkCreateAppKVSecretsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SecretServiceBulkCreateAppKVSecretsBody) contextValidateConflicts(ctx context.Context, formats strfmt.Registry) error {

	if m.Conflicts != nil {

		if swag.IsZero(m.Conflicts) { // not required
			return nil
		}

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

	return nil
}

func (m *SecretServiceBulkCreateAppKVSecretsBody) contextValidateSecrets(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Secrets[i] != nil {

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

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

	}

	return nil
}

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

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