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

// V1alpha1VerifiableCredential DataModel represents the W3C Verifiable Credential Data Model defined [here]
//
// swagger:model v1alpha1VerifiableCredential
//
// [here]: https://www.w3.org/TR/vc-data-model/
type V1alpha1VerifiableCredential struct {

	// https://www.w3.org/TR/vc-data-model/#contexts
	Context []string `json:"context"`

	// https://www.w3.org/TR/vc-data-model-2.0/#data-schemas
	CredentialSchema []*V1alpha1CredentialSchema `json:"credentialSchema"`

	// https://www.w3.org/TR/vc-data-model-2.0/#status
	CredentialStatus []*V1alpha1CredentialStatus `json:"credentialStatus"`

	// https://www.w3.org/TR/vc-data-model/#credential-subject
	CredentialSubject *V1alpha1BadgeClaims `json:"credentialSubject,omitempty"`

	// https://www.w3.org/TR/vc-data-model/#expiration
	ExpirationDate string `json:"expirationDate,omitempty"`

	// https://www.w3.org/TR/vc-data-model/#identifiers
	ID string `json:"id,omitempty"`

	// https://www.w3.org/TR/vc-data-model/#issuance-date
	IssuanceDate string `json:"issuanceDate,omitempty"`

	// https://www.w3.org/TR/vc-data-model/#issuer
	Issuer string `json:"issuer,omitempty"`

	// https://w3id.org/security#proof
	Proof *V1alpha1Proof `json:"proof,omitempty"`

	// https://www.w3.org/TR/vc-data-model/#dfn-type
	Type []string `json:"type"`
}

// Validate validates this v1alpha1 verifiable credential
func (m *V1alpha1VerifiableCredential) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *V1alpha1VerifiableCredential) validateCredentialSchema(formats strfmt.Registry) error {
	if swag.IsZero(m.CredentialSchema) { // not required
		return nil
	}

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

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

				return err
			}
		}

	}

	return nil
}

func (m *V1alpha1VerifiableCredential) validateCredentialStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.CredentialStatus) { // not required
		return nil
	}

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

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

				return err
			}
		}

	}

	return nil
}

func (m *V1alpha1VerifiableCredential) validateCredentialSubject(formats strfmt.Registry) error {
	if swag.IsZero(m.CredentialSubject) { // not required
		return nil
	}

	if m.CredentialSubject != nil {
		if err := m.CredentialSubject.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("credentialSubject")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("credentialSubject")
			}

			return err
		}
	}

	return nil
}

func (m *V1alpha1VerifiableCredential) validateProof(formats strfmt.Registry) error {
	if swag.IsZero(m.Proof) { // not required
		return nil
	}

	if m.Proof != nil {
		if err := m.Proof.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("proof")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("proof")
			}

			return err
		}
	}

	return nil
}

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

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

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

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

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

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

func (m *V1alpha1VerifiableCredential) contextValidateCredentialSchema(ctx context.Context, formats strfmt.Registry) error {

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

		if m.CredentialSchema[i] != nil {

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

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

				return err
			}
		}

	}

	return nil
}

func (m *V1alpha1VerifiableCredential) contextValidateCredentialStatus(ctx context.Context, formats strfmt.Registry) error {

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

		if m.CredentialStatus[i] != nil {

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

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

				return err
			}
		}

	}

	return nil
}

func (m *V1alpha1VerifiableCredential) contextValidateCredentialSubject(ctx context.Context, formats strfmt.Registry) error {

	if m.CredentialSubject != nil {

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

		if err := m.CredentialSubject.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("credentialSubject")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("credentialSubject")
			}

			return err
		}
	}

	return nil
}

func (m *V1alpha1VerifiableCredential) contextValidateProof(ctx context.Context, formats strfmt.Registry) error {

	if m.Proof != nil {

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

		if err := m.Proof.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("proof")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("proof")
			}

			return err
		}
	}

	return nil
}

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

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