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

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

// RPCGetUserAuthorizationResponse rpc get user authorization response
//
// swagger:model rpcGetUserAuthorizationResponse
type RPCGetUserAuthorizationResponse struct {

	// cluster role bindings
	ClusterRoleBindings []*ControllerStepObject `json:"clusterRoleBindings"`

	// cluster roles
	ClusterRoles []*ControllerStepObject `json:"clusterRoles"`

	// delete cluster role bindings
	DeleteClusterRoleBindings []*ControllerStepObject `json:"deleteClusterRoleBindings"`

	// delete role bindings
	DeleteRoleBindings []*ControllerStepObject `json:"deleteRoleBindings"`

	// enforce org admin only secret access
	EnforceOrgAdminOnlySecretAccess bool `json:"enforceOrgAdminOnlySecretAccess,omitempty"`

	// is org admin
	IsOrgAdmin bool `json:"isOrgAdmin,omitempty"`

	// is read
	IsRead bool `json:"isRead,omitempty"`

	// namespaces
	Namespaces []*ControllerStepObject `json:"namespaces"`

	// role bindings
	RoleBindings []*ControllerStepObject `json:"roleBindings"`

	// role name
	RoleName string `json:"roleName,omitempty"`

	// roles
	Roles []*ControllerStepObject `json:"roles"`

	// service account
	ServiceAccount *ControllerStepObject `json:"serviceAccount,omitempty"`

	// user name
	UserName string `json:"userName,omitempty"`
}

// Validate validates this rpc get user authorization response
func (m *RPCGetUserAuthorizationResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

func (m *RPCGetUserAuthorizationResponse) validateClusterRoleBindings(formats strfmt.Registry) error {
	if swag.IsZero(m.ClusterRoleBindings) { // not required
		return nil
	}

	for i := 0; i < len(m.ClusterRoleBindings); i++ {
		if swag.IsZero(m.ClusterRoleBindings[i]) { // not required
			continue
		}

		if m.ClusterRoleBindings[i] != nil {
			if err := m.ClusterRoleBindings[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("clusterRoleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("clusterRoleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateClusterRoles(formats strfmt.Registry) error {
	if swag.IsZero(m.ClusterRoles) { // not required
		return nil
	}

	for i := 0; i < len(m.ClusterRoles); i++ {
		if swag.IsZero(m.ClusterRoles[i]) { // not required
			continue
		}

		if m.ClusterRoles[i] != nil {
			if err := m.ClusterRoles[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("clusterRoles" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("clusterRoles" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateDeleteClusterRoleBindings(formats strfmt.Registry) error {
	if swag.IsZero(m.DeleteClusterRoleBindings) { // not required
		return nil
	}

	for i := 0; i < len(m.DeleteClusterRoleBindings); i++ {
		if swag.IsZero(m.DeleteClusterRoleBindings[i]) { // not required
			continue
		}

		if m.DeleteClusterRoleBindings[i] != nil {
			if err := m.DeleteClusterRoleBindings[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("deleteClusterRoleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("deleteClusterRoleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateDeleteRoleBindings(formats strfmt.Registry) error {
	if swag.IsZero(m.DeleteRoleBindings) { // not required
		return nil
	}

	for i := 0; i < len(m.DeleteRoleBindings); i++ {
		if swag.IsZero(m.DeleteRoleBindings[i]) { // not required
			continue
		}

		if m.DeleteRoleBindings[i] != nil {
			if err := m.DeleteRoleBindings[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("deleteRoleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("deleteRoleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateNamespaces(formats strfmt.Registry) error {
	if swag.IsZero(m.Namespaces) { // not required
		return nil
	}

	for i := 0; i < len(m.Namespaces); i++ {
		if swag.IsZero(m.Namespaces[i]) { // not required
			continue
		}

		if m.Namespaces[i] != nil {
			if err := m.Namespaces[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("namespaces" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("namespaces" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateRoleBindings(formats strfmt.Registry) error {
	if swag.IsZero(m.RoleBindings) { // not required
		return nil
	}

	for i := 0; i < len(m.RoleBindings); i++ {
		if swag.IsZero(m.RoleBindings[i]) { // not required
			continue
		}

		if m.RoleBindings[i] != nil {
			if err := m.RoleBindings[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("roleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("roleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateRoles(formats strfmt.Registry) error {
	if swag.IsZero(m.Roles) { // not required
		return nil
	}

	for i := 0; i < len(m.Roles); i++ {
		if swag.IsZero(m.Roles[i]) { // not required
			continue
		}

		if m.Roles[i] != nil {
			if err := m.Roles[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("roles" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("roles" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) validateServiceAccount(formats strfmt.Registry) error {
	if swag.IsZero(m.ServiceAccount) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this rpc get user authorization response based on the context it is used
func (m *RPCGetUserAuthorizationResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

func (m *RPCGetUserAuthorizationResponse) contextValidateClusterRoleBindings(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.ClusterRoleBindings); i++ {

		if m.ClusterRoleBindings[i] != nil {
			if err := m.ClusterRoleBindings[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("clusterRoleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("clusterRoleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateClusterRoles(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.ClusterRoles); i++ {

		if m.ClusterRoles[i] != nil {
			if err := m.ClusterRoles[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("clusterRoles" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("clusterRoles" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateDeleteClusterRoleBindings(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.DeleteClusterRoleBindings); i++ {

		if m.DeleteClusterRoleBindings[i] != nil {
			if err := m.DeleteClusterRoleBindings[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("deleteClusterRoleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("deleteClusterRoleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateDeleteRoleBindings(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.DeleteRoleBindings); i++ {

		if m.DeleteRoleBindings[i] != nil {
			if err := m.DeleteRoleBindings[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("deleteRoleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("deleteRoleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateNamespaces(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Namespaces); i++ {

		if m.Namespaces[i] != nil {
			if err := m.Namespaces[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("namespaces" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("namespaces" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateRoleBindings(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.RoleBindings); i++ {

		if m.RoleBindings[i] != nil {
			if err := m.RoleBindings[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("roleBindings" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("roleBindings" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateRoles(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Roles); i++ {

		if m.Roles[i] != nil {
			if err := m.Roles[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("roles" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("roles" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RPCGetUserAuthorizationResponse) contextValidateServiceAccount(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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