// 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"
	stderrors "errors"
	"strconv"

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

// V1alpha1ResolverMetadata ResolverMetadata represents a set of data describing the ID including mechanisms such as:
//   - cryptographic public keys - used to authenticate itself and prove
//     association with the ID
//   - service - ways of communicating with the node that published the document
//
// A ResolverMetadata can be retrieved by resolving an ID.
//
// swagger:model v1alpha1ResolverMetadata
type V1alpha1ResolverMetadata struct {

	// AssertionMethod is used to specify how the entity represented by the ID
	// is expected to express claims, such as for the purposes of issuing a VCs.
	AssertionMethod []string `json:"assertionMethod"`

	// A controller is an entity that is authorized to make changes to a Resolver Metadata.
	Controller string `json:"controller,omitempty"`

	// The ID
	// The metadata below is related as claims to the ID
	ID string `json:"id,omitempty"`

	// Service is used in ResolverMetadatas to express ways of communicating with
	// the node that published the document.
	Service []*V1alpha1Service `json:"service"`

	// VerificationMethod is a list of cryptographic public keys, which can be used
	// to authenticate or authorize interactions with the entities represented by the ID.
	VerificationMethod []*V1alpha1VerificationMethod `json:"verificationMethod"`
}

// Validate validates this v1alpha1 resolver metadata
func (m *V1alpha1ResolverMetadata) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *V1alpha1ResolverMetadata) validateService(formats strfmt.Registry) error {
	if swag.IsZero(m.Service) { // not required
		return nil
	}

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

		if m.Service[i] != nil {
			if err := m.Service[i].Validate(formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("service" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("service" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

func (m *V1alpha1ResolverMetadata) validateVerificationMethod(formats strfmt.Registry) error {
	if swag.IsZero(m.VerificationMethod) { // not required
		return nil
	}

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

		if m.VerificationMethod[i] != nil {
			if err := m.VerificationMethod[i].Validate(formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("verificationMethod" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("verificationMethod" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this v1alpha1 resolver metadata based on the context it is used
func (m *V1alpha1ResolverMetadata) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *V1alpha1ResolverMetadata) contextValidateService(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Service[i] != nil {

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

			if err := m.Service[i].ContextValidate(ctx, formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("service" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("service" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

func (m *V1alpha1ResolverMetadata) contextValidateVerificationMethod(ctx context.Context, formats strfmt.Registry) error {

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

		if m.VerificationMethod[i] != nil {

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

			if err := m.VerificationMethod[i].ContextValidate(ctx, formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("verificationMethod" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("verificationMethod" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

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

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