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

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

// V1alpha1PublishRequest Request to publish an issued Verifiable Credential
//
// swagger:model v1alpha1PublishRequest
type V1alpha1PublishRequest struct {

	// Optional Proof of ownership of the Issuer's ResolverMetadata
	// This should be provided when the Issuer is provided by an external IdP
	// Example: a signed JWT
	Proof *V1alpha1Proof `json:"proof,omitempty"`

	// The Verifiable Credential to publish
	Vc *V1alpha1EnvelopedCredential `json:"vc,omitempty"`
}

// Validate validates this v1alpha1 publish request
func (m *V1alpha1PublishRequest) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *V1alpha1PublishRequest) 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
}

func (m *V1alpha1PublishRequest) validateVc(formats strfmt.Registry) error {
	if swag.IsZero(m.Vc) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

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

func (m *V1alpha1PublishRequest) 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
}

func (m *V1alpha1PublishRequest) contextValidateVc(ctx context.Context, formats strfmt.Registry) error {

	if m.Vc != nil {

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

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

			return err
		}
	}

	return nil
}

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

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