// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/dialect/sql/sqljson"
	"entgo.io/ent/schema/field"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/apitoken"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/casbackend"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/group"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/integration"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/membership"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/organization"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/predicate"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/project"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflow"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontract"
	"github.com/google/uuid"
)

// OrganizationUpdate is the builder for updating Organization entities.
type OrganizationUpdate struct {
	config
	hooks     []Hook
	mutation  *OrganizationMutation
	modifiers []func(*sql.UpdateBuilder)
}

// Where appends a list predicates to the OrganizationUpdate builder.
func (ou *OrganizationUpdate) Where(ps ...predicate.Organization) *OrganizationUpdate {
	ou.mutation.Where(ps...)
	return ou
}

// SetName sets the "name" field.
func (ou *OrganizationUpdate) SetName(s string) *OrganizationUpdate {
	ou.mutation.SetName(s)
	return ou
}

// SetNillableName sets the "name" field if the given value is not nil.
func (ou *OrganizationUpdate) SetNillableName(s *string) *OrganizationUpdate {
	if s != nil {
		ou.SetName(*s)
	}
	return ou
}

// SetUpdatedAt sets the "updated_at" field.
func (ou *OrganizationUpdate) SetUpdatedAt(t time.Time) *OrganizationUpdate {
	ou.mutation.SetUpdatedAt(t)
	return ou
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (ou *OrganizationUpdate) SetNillableUpdatedAt(t *time.Time) *OrganizationUpdate {
	if t != nil {
		ou.SetUpdatedAt(*t)
	}
	return ou
}

// SetDeletedAt sets the "deleted_at" field.
func (ou *OrganizationUpdate) SetDeletedAt(t time.Time) *OrganizationUpdate {
	ou.mutation.SetDeletedAt(t)
	return ou
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (ou *OrganizationUpdate) SetNillableDeletedAt(t *time.Time) *OrganizationUpdate {
	if t != nil {
		ou.SetDeletedAt(*t)
	}
	return ou
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (ou *OrganizationUpdate) ClearDeletedAt() *OrganizationUpdate {
	ou.mutation.ClearDeletedAt()
	return ou
}

// SetBlockOnPolicyViolation sets the "block_on_policy_violation" field.
func (ou *OrganizationUpdate) SetBlockOnPolicyViolation(b bool) *OrganizationUpdate {
	ou.mutation.SetBlockOnPolicyViolation(b)
	return ou
}

// SetNillableBlockOnPolicyViolation sets the "block_on_policy_violation" field if the given value is not nil.
func (ou *OrganizationUpdate) SetNillableBlockOnPolicyViolation(b *bool) *OrganizationUpdate {
	if b != nil {
		ou.SetBlockOnPolicyViolation(*b)
	}
	return ou
}

// SetPoliciesAllowedHostnames sets the "policies_allowed_hostnames" field.
func (ou *OrganizationUpdate) SetPoliciesAllowedHostnames(s []string) *OrganizationUpdate {
	ou.mutation.SetPoliciesAllowedHostnames(s)
	return ou
}

// AppendPoliciesAllowedHostnames appends s to the "policies_allowed_hostnames" field.
func (ou *OrganizationUpdate) AppendPoliciesAllowedHostnames(s []string) *OrganizationUpdate {
	ou.mutation.AppendPoliciesAllowedHostnames(s)
	return ou
}

// ClearPoliciesAllowedHostnames clears the value of the "policies_allowed_hostnames" field.
func (ou *OrganizationUpdate) ClearPoliciesAllowedHostnames() *OrganizationUpdate {
	ou.mutation.ClearPoliciesAllowedHostnames()
	return ou
}

// AddMembershipIDs adds the "memberships" edge to the Membership entity by IDs.
func (ou *OrganizationUpdate) AddMembershipIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddMembershipIDs(ids...)
	return ou
}

// AddMemberships adds the "memberships" edges to the Membership entity.
func (ou *OrganizationUpdate) AddMemberships(m ...*Membership) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return ou.AddMembershipIDs(ids...)
}

// AddWorkflowContractIDs adds the "workflow_contracts" edge to the WorkflowContract entity by IDs.
func (ou *OrganizationUpdate) AddWorkflowContractIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddWorkflowContractIDs(ids...)
	return ou
}

// AddWorkflowContracts adds the "workflow_contracts" edges to the WorkflowContract entity.
func (ou *OrganizationUpdate) AddWorkflowContracts(w ...*WorkflowContract) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ou.AddWorkflowContractIDs(ids...)
}

// AddWorkflowIDs adds the "workflows" edge to the Workflow entity by IDs.
func (ou *OrganizationUpdate) AddWorkflowIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddWorkflowIDs(ids...)
	return ou
}

// AddWorkflows adds the "workflows" edges to the Workflow entity.
func (ou *OrganizationUpdate) AddWorkflows(w ...*Workflow) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ou.AddWorkflowIDs(ids...)
}

// AddCasBackendIDs adds the "cas_backends" edge to the CASBackend entity by IDs.
func (ou *OrganizationUpdate) AddCasBackendIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddCasBackendIDs(ids...)
	return ou
}

// AddCasBackends adds the "cas_backends" edges to the CASBackend entity.
func (ou *OrganizationUpdate) AddCasBackends(c ...*CASBackend) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return ou.AddCasBackendIDs(ids...)
}

// AddIntegrationIDs adds the "integrations" edge to the Integration entity by IDs.
func (ou *OrganizationUpdate) AddIntegrationIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddIntegrationIDs(ids...)
	return ou
}

// AddIntegrations adds the "integrations" edges to the Integration entity.
func (ou *OrganizationUpdate) AddIntegrations(i ...*Integration) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return ou.AddIntegrationIDs(ids...)
}

// AddAPITokenIDs adds the "api_tokens" edge to the APIToken entity by IDs.
func (ou *OrganizationUpdate) AddAPITokenIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddAPITokenIDs(ids...)
	return ou
}

// AddAPITokens adds the "api_tokens" edges to the APIToken entity.
func (ou *OrganizationUpdate) AddAPITokens(a ...*APIToken) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return ou.AddAPITokenIDs(ids...)
}

// AddProjectIDs adds the "projects" edge to the Project entity by IDs.
func (ou *OrganizationUpdate) AddProjectIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddProjectIDs(ids...)
	return ou
}

// AddProjects adds the "projects" edges to the Project entity.
func (ou *OrganizationUpdate) AddProjects(p ...*Project) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return ou.AddProjectIDs(ids...)
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (ou *OrganizationUpdate) AddGroupIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.AddGroupIDs(ids...)
	return ou
}

// AddGroups adds the "groups" edges to the Group entity.
func (ou *OrganizationUpdate) AddGroups(g ...*Group) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return ou.AddGroupIDs(ids...)
}

// Mutation returns the OrganizationMutation object of the builder.
func (ou *OrganizationUpdate) Mutation() *OrganizationMutation {
	return ou.mutation
}

// ClearMemberships clears all "memberships" edges to the Membership entity.
func (ou *OrganizationUpdate) ClearMemberships() *OrganizationUpdate {
	ou.mutation.ClearMemberships()
	return ou
}

// RemoveMembershipIDs removes the "memberships" edge to Membership entities by IDs.
func (ou *OrganizationUpdate) RemoveMembershipIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveMembershipIDs(ids...)
	return ou
}

// RemoveMemberships removes "memberships" edges to Membership entities.
func (ou *OrganizationUpdate) RemoveMemberships(m ...*Membership) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return ou.RemoveMembershipIDs(ids...)
}

// ClearWorkflowContracts clears all "workflow_contracts" edges to the WorkflowContract entity.
func (ou *OrganizationUpdate) ClearWorkflowContracts() *OrganizationUpdate {
	ou.mutation.ClearWorkflowContracts()
	return ou
}

// RemoveWorkflowContractIDs removes the "workflow_contracts" edge to WorkflowContract entities by IDs.
func (ou *OrganizationUpdate) RemoveWorkflowContractIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveWorkflowContractIDs(ids...)
	return ou
}

// RemoveWorkflowContracts removes "workflow_contracts" edges to WorkflowContract entities.
func (ou *OrganizationUpdate) RemoveWorkflowContracts(w ...*WorkflowContract) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ou.RemoveWorkflowContractIDs(ids...)
}

// ClearWorkflows clears all "workflows" edges to the Workflow entity.
func (ou *OrganizationUpdate) ClearWorkflows() *OrganizationUpdate {
	ou.mutation.ClearWorkflows()
	return ou
}

// RemoveWorkflowIDs removes the "workflows" edge to Workflow entities by IDs.
func (ou *OrganizationUpdate) RemoveWorkflowIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveWorkflowIDs(ids...)
	return ou
}

// RemoveWorkflows removes "workflows" edges to Workflow entities.
func (ou *OrganizationUpdate) RemoveWorkflows(w ...*Workflow) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ou.RemoveWorkflowIDs(ids...)
}

// ClearCasBackends clears all "cas_backends" edges to the CASBackend entity.
func (ou *OrganizationUpdate) ClearCasBackends() *OrganizationUpdate {
	ou.mutation.ClearCasBackends()
	return ou
}

// RemoveCasBackendIDs removes the "cas_backends" edge to CASBackend entities by IDs.
func (ou *OrganizationUpdate) RemoveCasBackendIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveCasBackendIDs(ids...)
	return ou
}

// RemoveCasBackends removes "cas_backends" edges to CASBackend entities.
func (ou *OrganizationUpdate) RemoveCasBackends(c ...*CASBackend) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return ou.RemoveCasBackendIDs(ids...)
}

// ClearIntegrations clears all "integrations" edges to the Integration entity.
func (ou *OrganizationUpdate) ClearIntegrations() *OrganizationUpdate {
	ou.mutation.ClearIntegrations()
	return ou
}

// RemoveIntegrationIDs removes the "integrations" edge to Integration entities by IDs.
func (ou *OrganizationUpdate) RemoveIntegrationIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveIntegrationIDs(ids...)
	return ou
}

// RemoveIntegrations removes "integrations" edges to Integration entities.
func (ou *OrganizationUpdate) RemoveIntegrations(i ...*Integration) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return ou.RemoveIntegrationIDs(ids...)
}

// ClearAPITokens clears all "api_tokens" edges to the APIToken entity.
func (ou *OrganizationUpdate) ClearAPITokens() *OrganizationUpdate {
	ou.mutation.ClearAPITokens()
	return ou
}

// RemoveAPITokenIDs removes the "api_tokens" edge to APIToken entities by IDs.
func (ou *OrganizationUpdate) RemoveAPITokenIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveAPITokenIDs(ids...)
	return ou
}

// RemoveAPITokens removes "api_tokens" edges to APIToken entities.
func (ou *OrganizationUpdate) RemoveAPITokens(a ...*APIToken) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return ou.RemoveAPITokenIDs(ids...)
}

// ClearProjects clears all "projects" edges to the Project entity.
func (ou *OrganizationUpdate) ClearProjects() *OrganizationUpdate {
	ou.mutation.ClearProjects()
	return ou
}

// RemoveProjectIDs removes the "projects" edge to Project entities by IDs.
func (ou *OrganizationUpdate) RemoveProjectIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveProjectIDs(ids...)
	return ou
}

// RemoveProjects removes "projects" edges to Project entities.
func (ou *OrganizationUpdate) RemoveProjects(p ...*Project) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return ou.RemoveProjectIDs(ids...)
}

// ClearGroups clears all "groups" edges to the Group entity.
func (ou *OrganizationUpdate) ClearGroups() *OrganizationUpdate {
	ou.mutation.ClearGroups()
	return ou
}

// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (ou *OrganizationUpdate) RemoveGroupIDs(ids ...uuid.UUID) *OrganizationUpdate {
	ou.mutation.RemoveGroupIDs(ids...)
	return ou
}

// RemoveGroups removes "groups" edges to Group entities.
func (ou *OrganizationUpdate) RemoveGroups(g ...*Group) *OrganizationUpdate {
	ids := make([]uuid.UUID, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return ou.RemoveGroupIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (ou *OrganizationUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, ou.sqlSave, ou.mutation, ou.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (ou *OrganizationUpdate) SaveX(ctx context.Context) int {
	affected, err := ou.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (ou *OrganizationUpdate) Exec(ctx context.Context) error {
	_, err := ou.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (ou *OrganizationUpdate) ExecX(ctx context.Context) {
	if err := ou.Exec(ctx); err != nil {
		panic(err)
	}
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (ou *OrganizationUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *OrganizationUpdate {
	ou.modifiers = append(ou.modifiers, modifiers...)
	return ou
}

func (ou *OrganizationUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(organization.Table, organization.Columns, sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID))
	if ps := ou.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ou.mutation.Name(); ok {
		_spec.SetField(organization.FieldName, field.TypeString, value)
	}
	if value, ok := ou.mutation.UpdatedAt(); ok {
		_spec.SetField(organization.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := ou.mutation.DeletedAt(); ok {
		_spec.SetField(organization.FieldDeletedAt, field.TypeTime, value)
	}
	if ou.mutation.DeletedAtCleared() {
		_spec.ClearField(organization.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := ou.mutation.BlockOnPolicyViolation(); ok {
		_spec.SetField(organization.FieldBlockOnPolicyViolation, field.TypeBool, value)
	}
	if value, ok := ou.mutation.PoliciesAllowedHostnames(); ok {
		_spec.SetField(organization.FieldPoliciesAllowedHostnames, field.TypeJSON, value)
	}
	if value, ok := ou.mutation.AppendedPoliciesAllowedHostnames(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, organization.FieldPoliciesAllowedHostnames, value)
		})
	}
	if ou.mutation.PoliciesAllowedHostnamesCleared() {
		_spec.ClearField(organization.FieldPoliciesAllowedHostnames, field.TypeJSON)
	}
	if ou.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.MembershipsTable,
			Columns: []string{organization.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(membership.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedMembershipsIDs(); len(nodes) > 0 && !ou.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.MembershipsTable,
			Columns: []string{organization.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(membership.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.MembershipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.MembershipsTable,
			Columns: []string{organization.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(membership.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.WorkflowContractsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowContractsTable,
			Columns: []string{organization.WorkflowContractsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedWorkflowContractsIDs(); len(nodes) > 0 && !ou.mutation.WorkflowContractsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowContractsTable,
			Columns: []string{organization.WorkflowContractsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.WorkflowContractsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowContractsTable,
			Columns: []string{organization.WorkflowContractsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.WorkflowsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowsTable,
			Columns: []string{organization.WorkflowsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedWorkflowsIDs(); len(nodes) > 0 && !ou.mutation.WorkflowsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowsTable,
			Columns: []string{organization.WorkflowsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.WorkflowsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowsTable,
			Columns: []string{organization.WorkflowsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.CasBackendsTable,
			Columns: []string{organization.CasBackendsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedCasBackendsIDs(); len(nodes) > 0 && !ou.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.CasBackendsTable,
			Columns: []string{organization.CasBackendsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.CasBackendsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.CasBackendsTable,
			Columns: []string{organization.CasBackendsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.IntegrationsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.IntegrationsTable,
			Columns: []string{organization.IntegrationsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integration.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedIntegrationsIDs(); len(nodes) > 0 && !ou.mutation.IntegrationsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.IntegrationsTable,
			Columns: []string{organization.IntegrationsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integration.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.IntegrationsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.IntegrationsTable,
			Columns: []string{organization.IntegrationsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integration.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.APITokensCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.APITokensTable,
			Columns: []string{organization.APITokensColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apitoken.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedAPITokensIDs(); len(nodes) > 0 && !ou.mutation.APITokensCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.APITokensTable,
			Columns: []string{organization.APITokensColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apitoken.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.APITokensIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.APITokensTable,
			Columns: []string{organization.APITokensColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apitoken.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.ProjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.ProjectsTable,
			Columns: []string{organization.ProjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedProjectsIDs(); len(nodes) > 0 && !ou.mutation.ProjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.ProjectsTable,
			Columns: []string{organization.ProjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.ProjectsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.ProjectsTable,
			Columns: []string{organization.ProjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ou.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.GroupsTable,
			Columns: []string{organization.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !ou.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.GroupsTable,
			Columns: []string{organization.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ou.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.GroupsTable,
			Columns: []string{organization.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(ou.modifiers...)
	if n, err = sqlgraph.UpdateNodes(ctx, ou.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{organization.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	ou.mutation.done = true
	return n, nil
}

// OrganizationUpdateOne is the builder for updating a single Organization entity.
type OrganizationUpdateOne struct {
	config
	fields    []string
	hooks     []Hook
	mutation  *OrganizationMutation
	modifiers []func(*sql.UpdateBuilder)
}

// SetName sets the "name" field.
func (ouo *OrganizationUpdateOne) SetName(s string) *OrganizationUpdateOne {
	ouo.mutation.SetName(s)
	return ouo
}

// SetNillableName sets the "name" field if the given value is not nil.
func (ouo *OrganizationUpdateOne) SetNillableName(s *string) *OrganizationUpdateOne {
	if s != nil {
		ouo.SetName(*s)
	}
	return ouo
}

// SetUpdatedAt sets the "updated_at" field.
func (ouo *OrganizationUpdateOne) SetUpdatedAt(t time.Time) *OrganizationUpdateOne {
	ouo.mutation.SetUpdatedAt(t)
	return ouo
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (ouo *OrganizationUpdateOne) SetNillableUpdatedAt(t *time.Time) *OrganizationUpdateOne {
	if t != nil {
		ouo.SetUpdatedAt(*t)
	}
	return ouo
}

// SetDeletedAt sets the "deleted_at" field.
func (ouo *OrganizationUpdateOne) SetDeletedAt(t time.Time) *OrganizationUpdateOne {
	ouo.mutation.SetDeletedAt(t)
	return ouo
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (ouo *OrganizationUpdateOne) SetNillableDeletedAt(t *time.Time) *OrganizationUpdateOne {
	if t != nil {
		ouo.SetDeletedAt(*t)
	}
	return ouo
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (ouo *OrganizationUpdateOne) ClearDeletedAt() *OrganizationUpdateOne {
	ouo.mutation.ClearDeletedAt()
	return ouo
}

// SetBlockOnPolicyViolation sets the "block_on_policy_violation" field.
func (ouo *OrganizationUpdateOne) SetBlockOnPolicyViolation(b bool) *OrganizationUpdateOne {
	ouo.mutation.SetBlockOnPolicyViolation(b)
	return ouo
}

// SetNillableBlockOnPolicyViolation sets the "block_on_policy_violation" field if the given value is not nil.
func (ouo *OrganizationUpdateOne) SetNillableBlockOnPolicyViolation(b *bool) *OrganizationUpdateOne {
	if b != nil {
		ouo.SetBlockOnPolicyViolation(*b)
	}
	return ouo
}

// SetPoliciesAllowedHostnames sets the "policies_allowed_hostnames" field.
func (ouo *OrganizationUpdateOne) SetPoliciesAllowedHostnames(s []string) *OrganizationUpdateOne {
	ouo.mutation.SetPoliciesAllowedHostnames(s)
	return ouo
}

// AppendPoliciesAllowedHostnames appends s to the "policies_allowed_hostnames" field.
func (ouo *OrganizationUpdateOne) AppendPoliciesAllowedHostnames(s []string) *OrganizationUpdateOne {
	ouo.mutation.AppendPoliciesAllowedHostnames(s)
	return ouo
}

// ClearPoliciesAllowedHostnames clears the value of the "policies_allowed_hostnames" field.
func (ouo *OrganizationUpdateOne) ClearPoliciesAllowedHostnames() *OrganizationUpdateOne {
	ouo.mutation.ClearPoliciesAllowedHostnames()
	return ouo
}

// AddMembershipIDs adds the "memberships" edge to the Membership entity by IDs.
func (ouo *OrganizationUpdateOne) AddMembershipIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddMembershipIDs(ids...)
	return ouo
}

// AddMemberships adds the "memberships" edges to the Membership entity.
func (ouo *OrganizationUpdateOne) AddMemberships(m ...*Membership) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return ouo.AddMembershipIDs(ids...)
}

// AddWorkflowContractIDs adds the "workflow_contracts" edge to the WorkflowContract entity by IDs.
func (ouo *OrganizationUpdateOne) AddWorkflowContractIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddWorkflowContractIDs(ids...)
	return ouo
}

// AddWorkflowContracts adds the "workflow_contracts" edges to the WorkflowContract entity.
func (ouo *OrganizationUpdateOne) AddWorkflowContracts(w ...*WorkflowContract) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ouo.AddWorkflowContractIDs(ids...)
}

// AddWorkflowIDs adds the "workflows" edge to the Workflow entity by IDs.
func (ouo *OrganizationUpdateOne) AddWorkflowIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddWorkflowIDs(ids...)
	return ouo
}

// AddWorkflows adds the "workflows" edges to the Workflow entity.
func (ouo *OrganizationUpdateOne) AddWorkflows(w ...*Workflow) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ouo.AddWorkflowIDs(ids...)
}

// AddCasBackendIDs adds the "cas_backends" edge to the CASBackend entity by IDs.
func (ouo *OrganizationUpdateOne) AddCasBackendIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddCasBackendIDs(ids...)
	return ouo
}

// AddCasBackends adds the "cas_backends" edges to the CASBackend entity.
func (ouo *OrganizationUpdateOne) AddCasBackends(c ...*CASBackend) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return ouo.AddCasBackendIDs(ids...)
}

// AddIntegrationIDs adds the "integrations" edge to the Integration entity by IDs.
func (ouo *OrganizationUpdateOne) AddIntegrationIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddIntegrationIDs(ids...)
	return ouo
}

// AddIntegrations adds the "integrations" edges to the Integration entity.
func (ouo *OrganizationUpdateOne) AddIntegrations(i ...*Integration) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return ouo.AddIntegrationIDs(ids...)
}

// AddAPITokenIDs adds the "api_tokens" edge to the APIToken entity by IDs.
func (ouo *OrganizationUpdateOne) AddAPITokenIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddAPITokenIDs(ids...)
	return ouo
}

// AddAPITokens adds the "api_tokens" edges to the APIToken entity.
func (ouo *OrganizationUpdateOne) AddAPITokens(a ...*APIToken) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return ouo.AddAPITokenIDs(ids...)
}

// AddProjectIDs adds the "projects" edge to the Project entity by IDs.
func (ouo *OrganizationUpdateOne) AddProjectIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddProjectIDs(ids...)
	return ouo
}

// AddProjects adds the "projects" edges to the Project entity.
func (ouo *OrganizationUpdateOne) AddProjects(p ...*Project) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return ouo.AddProjectIDs(ids...)
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (ouo *OrganizationUpdateOne) AddGroupIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.AddGroupIDs(ids...)
	return ouo
}

// AddGroups adds the "groups" edges to the Group entity.
func (ouo *OrganizationUpdateOne) AddGroups(g ...*Group) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return ouo.AddGroupIDs(ids...)
}

// Mutation returns the OrganizationMutation object of the builder.
func (ouo *OrganizationUpdateOne) Mutation() *OrganizationMutation {
	return ouo.mutation
}

// ClearMemberships clears all "memberships" edges to the Membership entity.
func (ouo *OrganizationUpdateOne) ClearMemberships() *OrganizationUpdateOne {
	ouo.mutation.ClearMemberships()
	return ouo
}

// RemoveMembershipIDs removes the "memberships" edge to Membership entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveMembershipIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveMembershipIDs(ids...)
	return ouo
}

// RemoveMemberships removes "memberships" edges to Membership entities.
func (ouo *OrganizationUpdateOne) RemoveMemberships(m ...*Membership) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return ouo.RemoveMembershipIDs(ids...)
}

// ClearWorkflowContracts clears all "workflow_contracts" edges to the WorkflowContract entity.
func (ouo *OrganizationUpdateOne) ClearWorkflowContracts() *OrganizationUpdateOne {
	ouo.mutation.ClearWorkflowContracts()
	return ouo
}

// RemoveWorkflowContractIDs removes the "workflow_contracts" edge to WorkflowContract entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveWorkflowContractIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveWorkflowContractIDs(ids...)
	return ouo
}

// RemoveWorkflowContracts removes "workflow_contracts" edges to WorkflowContract entities.
func (ouo *OrganizationUpdateOne) RemoveWorkflowContracts(w ...*WorkflowContract) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ouo.RemoveWorkflowContractIDs(ids...)
}

// ClearWorkflows clears all "workflows" edges to the Workflow entity.
func (ouo *OrganizationUpdateOne) ClearWorkflows() *OrganizationUpdateOne {
	ouo.mutation.ClearWorkflows()
	return ouo
}

// RemoveWorkflowIDs removes the "workflows" edge to Workflow entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveWorkflowIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveWorkflowIDs(ids...)
	return ouo
}

// RemoveWorkflows removes "workflows" edges to Workflow entities.
func (ouo *OrganizationUpdateOne) RemoveWorkflows(w ...*Workflow) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return ouo.RemoveWorkflowIDs(ids...)
}

// ClearCasBackends clears all "cas_backends" edges to the CASBackend entity.
func (ouo *OrganizationUpdateOne) ClearCasBackends() *OrganizationUpdateOne {
	ouo.mutation.ClearCasBackends()
	return ouo
}

// RemoveCasBackendIDs removes the "cas_backends" edge to CASBackend entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveCasBackendIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveCasBackendIDs(ids...)
	return ouo
}

// RemoveCasBackends removes "cas_backends" edges to CASBackend entities.
func (ouo *OrganizationUpdateOne) RemoveCasBackends(c ...*CASBackend) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(c))
	for i := range c {
		ids[i] = c[i].ID
	}
	return ouo.RemoveCasBackendIDs(ids...)
}

// ClearIntegrations clears all "integrations" edges to the Integration entity.
func (ouo *OrganizationUpdateOne) ClearIntegrations() *OrganizationUpdateOne {
	ouo.mutation.ClearIntegrations()
	return ouo
}

// RemoveIntegrationIDs removes the "integrations" edge to Integration entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveIntegrationIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveIntegrationIDs(ids...)
	return ouo
}

// RemoveIntegrations removes "integrations" edges to Integration entities.
func (ouo *OrganizationUpdateOne) RemoveIntegrations(i ...*Integration) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return ouo.RemoveIntegrationIDs(ids...)
}

// ClearAPITokens clears all "api_tokens" edges to the APIToken entity.
func (ouo *OrganizationUpdateOne) ClearAPITokens() *OrganizationUpdateOne {
	ouo.mutation.ClearAPITokens()
	return ouo
}

// RemoveAPITokenIDs removes the "api_tokens" edge to APIToken entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveAPITokenIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveAPITokenIDs(ids...)
	return ouo
}

// RemoveAPITokens removes "api_tokens" edges to APIToken entities.
func (ouo *OrganizationUpdateOne) RemoveAPITokens(a ...*APIToken) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return ouo.RemoveAPITokenIDs(ids...)
}

// ClearProjects clears all "projects" edges to the Project entity.
func (ouo *OrganizationUpdateOne) ClearProjects() *OrganizationUpdateOne {
	ouo.mutation.ClearProjects()
	return ouo
}

// RemoveProjectIDs removes the "projects" edge to Project entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveProjectIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveProjectIDs(ids...)
	return ouo
}

// RemoveProjects removes "projects" edges to Project entities.
func (ouo *OrganizationUpdateOne) RemoveProjects(p ...*Project) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(p))
	for i := range p {
		ids[i] = p[i].ID
	}
	return ouo.RemoveProjectIDs(ids...)
}

// ClearGroups clears all "groups" edges to the Group entity.
func (ouo *OrganizationUpdateOne) ClearGroups() *OrganizationUpdateOne {
	ouo.mutation.ClearGroups()
	return ouo
}

// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (ouo *OrganizationUpdateOne) RemoveGroupIDs(ids ...uuid.UUID) *OrganizationUpdateOne {
	ouo.mutation.RemoveGroupIDs(ids...)
	return ouo
}

// RemoveGroups removes "groups" edges to Group entities.
func (ouo *OrganizationUpdateOne) RemoveGroups(g ...*Group) *OrganizationUpdateOne {
	ids := make([]uuid.UUID, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return ouo.RemoveGroupIDs(ids...)
}

// Where appends a list predicates to the OrganizationUpdate builder.
func (ouo *OrganizationUpdateOne) Where(ps ...predicate.Organization) *OrganizationUpdateOne {
	ouo.mutation.Where(ps...)
	return ouo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (ouo *OrganizationUpdateOne) Select(field string, fields ...string) *OrganizationUpdateOne {
	ouo.fields = append([]string{field}, fields...)
	return ouo
}

// Save executes the query and returns the updated Organization entity.
func (ouo *OrganizationUpdateOne) Save(ctx context.Context) (*Organization, error) {
	return withHooks(ctx, ouo.sqlSave, ouo.mutation, ouo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (ouo *OrganizationUpdateOne) SaveX(ctx context.Context) *Organization {
	node, err := ouo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (ouo *OrganizationUpdateOne) Exec(ctx context.Context) error {
	_, err := ouo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (ouo *OrganizationUpdateOne) ExecX(ctx context.Context) {
	if err := ouo.Exec(ctx); err != nil {
		panic(err)
	}
}

// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (ouo *OrganizationUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *OrganizationUpdateOne {
	ouo.modifiers = append(ouo.modifiers, modifiers...)
	return ouo
}

func (ouo *OrganizationUpdateOne) sqlSave(ctx context.Context) (_node *Organization, err error) {
	_spec := sqlgraph.NewUpdateSpec(organization.Table, organization.Columns, sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID))
	id, ok := ouo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Organization.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := ouo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, organization.FieldID)
		for _, f := range fields {
			if !organization.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != organization.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := ouo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ouo.mutation.Name(); ok {
		_spec.SetField(organization.FieldName, field.TypeString, value)
	}
	if value, ok := ouo.mutation.UpdatedAt(); ok {
		_spec.SetField(organization.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := ouo.mutation.DeletedAt(); ok {
		_spec.SetField(organization.FieldDeletedAt, field.TypeTime, value)
	}
	if ouo.mutation.DeletedAtCleared() {
		_spec.ClearField(organization.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := ouo.mutation.BlockOnPolicyViolation(); ok {
		_spec.SetField(organization.FieldBlockOnPolicyViolation, field.TypeBool, value)
	}
	if value, ok := ouo.mutation.PoliciesAllowedHostnames(); ok {
		_spec.SetField(organization.FieldPoliciesAllowedHostnames, field.TypeJSON, value)
	}
	if value, ok := ouo.mutation.AppendedPoliciesAllowedHostnames(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, organization.FieldPoliciesAllowedHostnames, value)
		})
	}
	if ouo.mutation.PoliciesAllowedHostnamesCleared() {
		_spec.ClearField(organization.FieldPoliciesAllowedHostnames, field.TypeJSON)
	}
	if ouo.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.MembershipsTable,
			Columns: []string{organization.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(membership.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedMembershipsIDs(); len(nodes) > 0 && !ouo.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.MembershipsTable,
			Columns: []string{organization.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(membership.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.MembershipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.MembershipsTable,
			Columns: []string{organization.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(membership.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.WorkflowContractsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowContractsTable,
			Columns: []string{organization.WorkflowContractsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedWorkflowContractsIDs(); len(nodes) > 0 && !ouo.mutation.WorkflowContractsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowContractsTable,
			Columns: []string{organization.WorkflowContractsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.WorkflowContractsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowContractsTable,
			Columns: []string{organization.WorkflowContractsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.WorkflowsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowsTable,
			Columns: []string{organization.WorkflowsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedWorkflowsIDs(); len(nodes) > 0 && !ouo.mutation.WorkflowsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowsTable,
			Columns: []string{organization.WorkflowsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.WorkflowsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.WorkflowsTable,
			Columns: []string{organization.WorkflowsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.CasBackendsTable,
			Columns: []string{organization.CasBackendsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedCasBackendsIDs(); len(nodes) > 0 && !ouo.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.CasBackendsTable,
			Columns: []string{organization.CasBackendsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.CasBackendsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.CasBackendsTable,
			Columns: []string{organization.CasBackendsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.IntegrationsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.IntegrationsTable,
			Columns: []string{organization.IntegrationsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integration.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedIntegrationsIDs(); len(nodes) > 0 && !ouo.mutation.IntegrationsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.IntegrationsTable,
			Columns: []string{organization.IntegrationsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integration.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.IntegrationsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.IntegrationsTable,
			Columns: []string{organization.IntegrationsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integration.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.APITokensCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.APITokensTable,
			Columns: []string{organization.APITokensColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apitoken.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedAPITokensIDs(); len(nodes) > 0 && !ouo.mutation.APITokensCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.APITokensTable,
			Columns: []string{organization.APITokensColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apitoken.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.APITokensIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.APITokensTable,
			Columns: []string{organization.APITokensColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apitoken.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.ProjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.ProjectsTable,
			Columns: []string{organization.ProjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedProjectsIDs(); len(nodes) > 0 && !ouo.mutation.ProjectsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.ProjectsTable,
			Columns: []string{organization.ProjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.ProjectsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.ProjectsTable,
			Columns: []string{organization.ProjectsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ouo.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.GroupsTable,
			Columns: []string{organization.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !ouo.mutation.GroupsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.GroupsTable,
			Columns: []string{organization.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ouo.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   organization.GroupsTable,
			Columns: []string{organization.GroupsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_spec.AddModifiers(ouo.modifiers...)
	_node = &Organization{config: ouo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, ouo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{organization.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	ouo.mutation.done = true
	return _node, nil
}
