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

// V1alpha1GenerateRequest Generate an Id and its corresponding ResolverMetadata for the specified Issuer
// For external IdPs, the Issuer should be provided with a Proof of ownership
// of the Issuer's provided id
//
// swagger:model v1alpha1GenerateRequest
type V1alpha1GenerateRequest struct {

	// The Issuer details
	Issuer *V1alpha1Issuer `json:"issuer,omitempty"`

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

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

	if err := m.validateIssuer(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 *V1alpha1GenerateRequest) validateIssuer(formats strfmt.Registry) error {
	if swag.IsZero(m.Issuer) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1GenerateRequest) 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 generate request based on the context it is used
func (m *V1alpha1GenerateRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateIssuer(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 *V1alpha1GenerateRequest) contextValidateIssuer(ctx context.Context, formats strfmt.Registry) error {

	if m.Issuer != nil {

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

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1GenerateRequest) 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 *V1alpha1GenerateRequest) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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