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

// V1alpha1Issuer A Identity Issuer
//
// swagger:model v1alpha1Issuer
type V1alpha1Issuer struct {

	// This field specifies the authentication mechanism used by the issuer.
	// It determines whether the issuer uses an external Identity Provider (IDP)
	// or a self-issued key for authentication.
	AuthType *V1alpha1IssuerAuthType `json:"authType,omitempty"`

	// The common name of the issuer
	// Could be a FQDN or a FQDA
	CommonName string `json:"commonName,omitempty"`

	// The organization of the issuer
	Organization string `json:"organization,omitempty"`

	// This field is optional
	// The private key of the issuer in JWK format
	PrivateKey *V1alpha1Jwk `json:"privateKey,omitempty"`

	// This field is optional
	// The keys of the issuer in JWK format
	// The public key is used to verify the signature of the different claims
	PublicKey *V1alpha1Jwk `json:"publicKey,omitempty"`

	// The sub organization of the issuer
	SubOrganization string `json:"subOrganization,omitempty"`

	// This will be set to true when issuer provides a valid proof of ownership
	// of the common name on registration
	Verified bool `json:"verified,omitempty"`
}

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

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

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

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

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

func (m *V1alpha1Issuer) validateAuthType(formats strfmt.Registry) error {
	if swag.IsZero(m.AuthType) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1Issuer) validatePrivateKey(formats strfmt.Registry) error {
	if swag.IsZero(m.PrivateKey) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1Issuer) validatePublicKey(formats strfmt.Registry) error {
	if swag.IsZero(m.PublicKey) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

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

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

func (m *V1alpha1Issuer) contextValidateAuthType(ctx context.Context, formats strfmt.Registry) error {

	if m.AuthType != nil {

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

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1Issuer) contextValidatePrivateKey(ctx context.Context, formats strfmt.Registry) error {

	if m.PrivateKey != nil {

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

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1Issuer) contextValidatePublicKey(ctx context.Context, formats strfmt.Registry) error {

	if m.PublicKey != nil {

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

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

			return err
		}
	}

	return nil
}

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

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