// 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"
	"github.com/go-openapi/validate"
)

// V1alpha1IssuerSettings Issuer Settings
//
// swagger:model v1alpha1IssuerSettings
type V1alpha1IssuerSettings struct {

	// Settings for the Duo Identity Provider.
	DuoIdpSettings *V1alpha1DuoIdpSettings `json:"duoIdpSettings,omitempty"`

	// The type of the IdP.
	// Required: true
	IdpType *V1alpha1IdpType `json:"idpType"`

	// A unique identifier for the Issuer.
	// This is typically the Issuer's ID in the Identity.
	// Read Only: true
	IssuerID string `json:"issuerId,omitempty"`

	// Settings for the Okta Identity Provider.
	OktaIdpSettings *V1alpha1OktaIdpSettings `json:"oktaIdpSettings,omitempty"`

	// Settings for the Ory Identity Provider.
	OryIdpSettings *V1alpha1OryIdpSettings `json:"oryIdpSettings,omitempty"`
}

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

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

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

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

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

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

func (m *V1alpha1IssuerSettings) validateDuoIdpSettings(formats strfmt.Registry) error {
	if swag.IsZero(m.DuoIdpSettings) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1IssuerSettings) validateIdpType(formats strfmt.Registry) error {

	if err := validate.Required("idpType", "body", m.IdpType); err != nil {
		return err
	}

	if err := validate.Required("idpType", "body", m.IdpType); err != nil {
		return err
	}

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1IssuerSettings) validateOktaIdpSettings(formats strfmt.Registry) error {
	if swag.IsZero(m.OktaIdpSettings) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1IssuerSettings) validateOryIdpSettings(formats strfmt.Registry) error {
	if swag.IsZero(m.OryIdpSettings) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

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

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

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

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

func (m *V1alpha1IssuerSettings) contextValidateDuoIdpSettings(ctx context.Context, formats strfmt.Registry) error {

	if m.DuoIdpSettings != nil {

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

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1IssuerSettings) contextValidateIdpType(ctx context.Context, formats strfmt.Registry) error {

	if m.IdpType != nil {

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1IssuerSettings) contextValidateIssuerID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "issuerId", "body", m.IssuerID); err != nil {
		return err
	}

	return nil
}

func (m *V1alpha1IssuerSettings) contextValidateOktaIdpSettings(ctx context.Context, formats strfmt.Registry) error {

	if m.OktaIdpSettings != nil {

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

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

			return err
		}
	}

	return nil
}

func (m *V1alpha1IssuerSettings) contextValidateOryIdpSettings(ctx context.Context, formats strfmt.Registry) error {

	if m.OryIdpSettings != nil {

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

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

			return err
		}
	}

	return nil
}

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

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