// Code generated by go-swagger; DO NOT EDIT.

package model

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"

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

// CentralOrgAuthMethod central org auth method
//
// swagger:model centralOrgAuthMethod
type CentralOrgAuthMethod struct {

	// allow email domain
	AllowEmailDomain []string `json:"allow_email_domain"`

	// auto provision
	AutoProvision bool `json:"auto_provision,omitempty"`

	// display name
	DisplayName string `json:"display_name,omitempty"`

	// name
	Name string `json:"name,omitempty"`

	// oidc config
	OidcConfig *CentralOidcConfig `json:"oidc_config,omitempty"`

	// saml config
	SamlConfig *CentralSamlConfig `json:"saml_config,omitempty"`

	// scim provision
	ScimProvision bool `json:"scim_provision,omitempty"`

	// status
	Status string `json:"status,omitempty"`

	// type
	Type string `json:"type,omitempty"`
}

// Validate validates this central org auth method
func (m *CentralOrgAuthMethod) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CentralOrgAuthMethod) validateOidcConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.OidcConfig) { // not required
		return nil
	}

	if m.OidcConfig != nil {
		if err := m.OidcConfig.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("oidc_config")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("oidc_config")
			}
			return err
		}
	}

	return nil
}

func (m *CentralOrgAuthMethod) validateSamlConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.SamlConfig) { // not required
		return nil
	}

	if m.SamlConfig != nil {
		if err := m.SamlConfig.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("saml_config")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("saml_config")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this central org auth method based on the context it is used
func (m *CentralOrgAuthMethod) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CentralOrgAuthMethod) contextValidateOidcConfig(ctx context.Context, formats strfmt.Registry) error {

	if m.OidcConfig != nil {

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

		if err := m.OidcConfig.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("oidc_config")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("oidc_config")
			}
			return err
		}
	}

	return nil
}

func (m *CentralOrgAuthMethod) contextValidateSamlConfig(ctx context.Context, formats strfmt.Registry) error {

	if m.SamlConfig != nil {

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

		if err := m.SamlConfig.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("saml_config")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("saml_config")
			}
			return err
		}
	}

	return nil
}

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

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