// 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/schema/field"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/integrationattachment"
	"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/referrer"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/robotaccount"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflow"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontract"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowrun"
	"github.com/google/uuid"
)

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

// Where appends a list predicates to the WorkflowUpdate builder.
func (wu *WorkflowUpdate) Where(ps ...predicate.Workflow) *WorkflowUpdate {
	wu.mutation.Where(ps...)
	return wu
}

// SetProjectOld sets the "project_old" field.
func (wu *WorkflowUpdate) SetProjectOld(s string) *WorkflowUpdate {
	wu.mutation.SetProjectOld(s)
	return wu
}

// SetNillableProjectOld sets the "project_old" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableProjectOld(s *string) *WorkflowUpdate {
	if s != nil {
		wu.SetProjectOld(*s)
	}
	return wu
}

// ClearProjectOld clears the value of the "project_old" field.
func (wu *WorkflowUpdate) ClearProjectOld() *WorkflowUpdate {
	wu.mutation.ClearProjectOld()
	return wu
}

// SetTeam sets the "team" field.
func (wu *WorkflowUpdate) SetTeam(s string) *WorkflowUpdate {
	wu.mutation.SetTeam(s)
	return wu
}

// SetNillableTeam sets the "team" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableTeam(s *string) *WorkflowUpdate {
	if s != nil {
		wu.SetTeam(*s)
	}
	return wu
}

// ClearTeam clears the value of the "team" field.
func (wu *WorkflowUpdate) ClearTeam() *WorkflowUpdate {
	wu.mutation.ClearTeam()
	return wu
}

// SetRunsCount sets the "runs_count" field.
func (wu *WorkflowUpdate) SetRunsCount(i int) *WorkflowUpdate {
	wu.mutation.ResetRunsCount()
	wu.mutation.SetRunsCount(i)
	return wu
}

// SetNillableRunsCount sets the "runs_count" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableRunsCount(i *int) *WorkflowUpdate {
	if i != nil {
		wu.SetRunsCount(*i)
	}
	return wu
}

// AddRunsCount adds i to the "runs_count" field.
func (wu *WorkflowUpdate) AddRunsCount(i int) *WorkflowUpdate {
	wu.mutation.AddRunsCount(i)
	return wu
}

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

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

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

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

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

// SetPublic sets the "public" field.
func (wu *WorkflowUpdate) SetPublic(b bool) *WorkflowUpdate {
	wu.mutation.SetPublic(b)
	return wu
}

// SetNillablePublic sets the "public" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillablePublic(b *bool) *WorkflowUpdate {
	if b != nil {
		wu.SetPublic(*b)
	}
	return wu
}

// SetOrganizationID sets the "organization_id" field.
func (wu *WorkflowUpdate) SetOrganizationID(u uuid.UUID) *WorkflowUpdate {
	wu.mutation.SetOrganizationID(u)
	return wu
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableOrganizationID(u *uuid.UUID) *WorkflowUpdate {
	if u != nil {
		wu.SetOrganizationID(*u)
	}
	return wu
}

// SetProjectID sets the "project_id" field.
func (wu *WorkflowUpdate) SetProjectID(u uuid.UUID) *WorkflowUpdate {
	wu.mutation.SetProjectID(u)
	return wu
}

// SetNillableProjectID sets the "project_id" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableProjectID(u *uuid.UUID) *WorkflowUpdate {
	if u != nil {
		wu.SetProjectID(*u)
	}
	return wu
}

// SetLatestRun sets the "latest_run" field.
func (wu *WorkflowUpdate) SetLatestRun(u uuid.UUID) *WorkflowUpdate {
	wu.mutation.SetLatestRun(u)
	return wu
}

// SetNillableLatestRun sets the "latest_run" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableLatestRun(u *uuid.UUID) *WorkflowUpdate {
	if u != nil {
		wu.SetLatestRun(*u)
	}
	return wu
}

// ClearLatestRun clears the value of the "latest_run" field.
func (wu *WorkflowUpdate) ClearLatestRun() *WorkflowUpdate {
	wu.mutation.ClearLatestRun()
	return wu
}

// SetDescription sets the "description" field.
func (wu *WorkflowUpdate) SetDescription(s string) *WorkflowUpdate {
	wu.mutation.SetDescription(s)
	return wu
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableDescription(s *string) *WorkflowUpdate {
	if s != nil {
		wu.SetDescription(*s)
	}
	return wu
}

// ClearDescription clears the value of the "description" field.
func (wu *WorkflowUpdate) ClearDescription() *WorkflowUpdate {
	wu.mutation.ClearDescription()
	return wu
}

// SetMetadata sets the "metadata" field.
func (wu *WorkflowUpdate) SetMetadata(m map[string]interface{}) *WorkflowUpdate {
	wu.mutation.SetMetadata(m)
	return wu
}

// ClearMetadata clears the value of the "metadata" field.
func (wu *WorkflowUpdate) ClearMetadata() *WorkflowUpdate {
	wu.mutation.ClearMetadata()
	return wu
}

// AddRobotaccountIDs adds the "robotaccounts" edge to the RobotAccount entity by IDs.
func (wu *WorkflowUpdate) AddRobotaccountIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.AddRobotaccountIDs(ids...)
	return wu
}

// AddRobotaccounts adds the "robotaccounts" edges to the RobotAccount entity.
func (wu *WorkflowUpdate) AddRobotaccounts(r ...*RobotAccount) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wu.AddRobotaccountIDs(ids...)
}

// AddWorkflowrunIDs adds the "workflowruns" edge to the WorkflowRun entity by IDs.
func (wu *WorkflowUpdate) AddWorkflowrunIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.AddWorkflowrunIDs(ids...)
	return wu
}

// AddWorkflowruns adds the "workflowruns" edges to the WorkflowRun entity.
func (wu *WorkflowUpdate) AddWorkflowruns(w ...*WorkflowRun) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return wu.AddWorkflowrunIDs(ids...)
}

// SetOrganization sets the "organization" edge to the Organization entity.
func (wu *WorkflowUpdate) SetOrganization(o *Organization) *WorkflowUpdate {
	return wu.SetOrganizationID(o.ID)
}

// SetContractID sets the "contract" edge to the WorkflowContract entity by ID.
func (wu *WorkflowUpdate) SetContractID(id uuid.UUID) *WorkflowUpdate {
	wu.mutation.SetContractID(id)
	return wu
}

// SetContract sets the "contract" edge to the WorkflowContract entity.
func (wu *WorkflowUpdate) SetContract(w *WorkflowContract) *WorkflowUpdate {
	return wu.SetContractID(w.ID)
}

// AddIntegrationAttachmentIDs adds the "integration_attachments" edge to the IntegrationAttachment entity by IDs.
func (wu *WorkflowUpdate) AddIntegrationAttachmentIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.AddIntegrationAttachmentIDs(ids...)
	return wu
}

// AddIntegrationAttachments adds the "integration_attachments" edges to the IntegrationAttachment entity.
func (wu *WorkflowUpdate) AddIntegrationAttachments(i ...*IntegrationAttachment) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return wu.AddIntegrationAttachmentIDs(ids...)
}

// SetProject sets the "project" edge to the Project entity.
func (wu *WorkflowUpdate) SetProject(p *Project) *WorkflowUpdate {
	return wu.SetProjectID(p.ID)
}

// SetLatestWorkflowRunID sets the "latest_workflow_run" edge to the WorkflowRun entity by ID.
func (wu *WorkflowUpdate) SetLatestWorkflowRunID(id uuid.UUID) *WorkflowUpdate {
	wu.mutation.SetLatestWorkflowRunID(id)
	return wu
}

// SetNillableLatestWorkflowRunID sets the "latest_workflow_run" edge to the WorkflowRun entity by ID if the given value is not nil.
func (wu *WorkflowUpdate) SetNillableLatestWorkflowRunID(id *uuid.UUID) *WorkflowUpdate {
	if id != nil {
		wu = wu.SetLatestWorkflowRunID(*id)
	}
	return wu
}

// SetLatestWorkflowRun sets the "latest_workflow_run" edge to the WorkflowRun entity.
func (wu *WorkflowUpdate) SetLatestWorkflowRun(w *WorkflowRun) *WorkflowUpdate {
	return wu.SetLatestWorkflowRunID(w.ID)
}

// AddReferrerIDs adds the "referrers" edge to the Referrer entity by IDs.
func (wu *WorkflowUpdate) AddReferrerIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.AddReferrerIDs(ids...)
	return wu
}

// AddReferrers adds the "referrers" edges to the Referrer entity.
func (wu *WorkflowUpdate) AddReferrers(r ...*Referrer) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wu.AddReferrerIDs(ids...)
}

// Mutation returns the WorkflowMutation object of the builder.
func (wu *WorkflowUpdate) Mutation() *WorkflowMutation {
	return wu.mutation
}

// ClearRobotaccounts clears all "robotaccounts" edges to the RobotAccount entity.
func (wu *WorkflowUpdate) ClearRobotaccounts() *WorkflowUpdate {
	wu.mutation.ClearRobotaccounts()
	return wu
}

// RemoveRobotaccountIDs removes the "robotaccounts" edge to RobotAccount entities by IDs.
func (wu *WorkflowUpdate) RemoveRobotaccountIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.RemoveRobotaccountIDs(ids...)
	return wu
}

// RemoveRobotaccounts removes "robotaccounts" edges to RobotAccount entities.
func (wu *WorkflowUpdate) RemoveRobotaccounts(r ...*RobotAccount) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wu.RemoveRobotaccountIDs(ids...)
}

// ClearWorkflowruns clears all "workflowruns" edges to the WorkflowRun entity.
func (wu *WorkflowUpdate) ClearWorkflowruns() *WorkflowUpdate {
	wu.mutation.ClearWorkflowruns()
	return wu
}

// RemoveWorkflowrunIDs removes the "workflowruns" edge to WorkflowRun entities by IDs.
func (wu *WorkflowUpdate) RemoveWorkflowrunIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.RemoveWorkflowrunIDs(ids...)
	return wu
}

// RemoveWorkflowruns removes "workflowruns" edges to WorkflowRun entities.
func (wu *WorkflowUpdate) RemoveWorkflowruns(w ...*WorkflowRun) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return wu.RemoveWorkflowrunIDs(ids...)
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (wu *WorkflowUpdate) ClearOrganization() *WorkflowUpdate {
	wu.mutation.ClearOrganization()
	return wu
}

// ClearContract clears the "contract" edge to the WorkflowContract entity.
func (wu *WorkflowUpdate) ClearContract() *WorkflowUpdate {
	wu.mutation.ClearContract()
	return wu
}

// ClearIntegrationAttachments clears all "integration_attachments" edges to the IntegrationAttachment entity.
func (wu *WorkflowUpdate) ClearIntegrationAttachments() *WorkflowUpdate {
	wu.mutation.ClearIntegrationAttachments()
	return wu
}

// RemoveIntegrationAttachmentIDs removes the "integration_attachments" edge to IntegrationAttachment entities by IDs.
func (wu *WorkflowUpdate) RemoveIntegrationAttachmentIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.RemoveIntegrationAttachmentIDs(ids...)
	return wu
}

// RemoveIntegrationAttachments removes "integration_attachments" edges to IntegrationAttachment entities.
func (wu *WorkflowUpdate) RemoveIntegrationAttachments(i ...*IntegrationAttachment) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return wu.RemoveIntegrationAttachmentIDs(ids...)
}

// ClearProject clears the "project" edge to the Project entity.
func (wu *WorkflowUpdate) ClearProject() *WorkflowUpdate {
	wu.mutation.ClearProject()
	return wu
}

// ClearLatestWorkflowRun clears the "latest_workflow_run" edge to the WorkflowRun entity.
func (wu *WorkflowUpdate) ClearLatestWorkflowRun() *WorkflowUpdate {
	wu.mutation.ClearLatestWorkflowRun()
	return wu
}

// ClearReferrers clears all "referrers" edges to the Referrer entity.
func (wu *WorkflowUpdate) ClearReferrers() *WorkflowUpdate {
	wu.mutation.ClearReferrers()
	return wu
}

// RemoveReferrerIDs removes the "referrers" edge to Referrer entities by IDs.
func (wu *WorkflowUpdate) RemoveReferrerIDs(ids ...uuid.UUID) *WorkflowUpdate {
	wu.mutation.RemoveReferrerIDs(ids...)
	return wu
}

// RemoveReferrers removes "referrers" edges to Referrer entities.
func (wu *WorkflowUpdate) RemoveReferrers(r ...*Referrer) *WorkflowUpdate {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wu.RemoveReferrerIDs(ids...)
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (wu *WorkflowUpdate) check() error {
	if wu.mutation.OrganizationCleared() && len(wu.mutation.OrganizationIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "Workflow.organization"`)
	}
	if wu.mutation.ContractCleared() && len(wu.mutation.ContractIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "Workflow.contract"`)
	}
	if wu.mutation.ProjectCleared() && len(wu.mutation.ProjectIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "Workflow.project"`)
	}
	return nil
}

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

func (wu *WorkflowUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := wu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(workflow.Table, workflow.Columns, sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID))
	if ps := wu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wu.mutation.ProjectOld(); ok {
		_spec.SetField(workflow.FieldProjectOld, field.TypeString, value)
	}
	if wu.mutation.ProjectOldCleared() {
		_spec.ClearField(workflow.FieldProjectOld, field.TypeString)
	}
	if value, ok := wu.mutation.Team(); ok {
		_spec.SetField(workflow.FieldTeam, field.TypeString, value)
	}
	if wu.mutation.TeamCleared() {
		_spec.ClearField(workflow.FieldTeam, field.TypeString)
	}
	if value, ok := wu.mutation.RunsCount(); ok {
		_spec.SetField(workflow.FieldRunsCount, field.TypeInt, value)
	}
	if value, ok := wu.mutation.AddedRunsCount(); ok {
		_spec.AddField(workflow.FieldRunsCount, field.TypeInt, value)
	}
	if value, ok := wu.mutation.UpdatedAt(); ok {
		_spec.SetField(workflow.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := wu.mutation.DeletedAt(); ok {
		_spec.SetField(workflow.FieldDeletedAt, field.TypeTime, value)
	}
	if wu.mutation.DeletedAtCleared() {
		_spec.ClearField(workflow.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := wu.mutation.Public(); ok {
		_spec.SetField(workflow.FieldPublic, field.TypeBool, value)
	}
	if value, ok := wu.mutation.Description(); ok {
		_spec.SetField(workflow.FieldDescription, field.TypeString, value)
	}
	if wu.mutation.DescriptionCleared() {
		_spec.ClearField(workflow.FieldDescription, field.TypeString)
	}
	if value, ok := wu.mutation.Metadata(); ok {
		_spec.SetField(workflow.FieldMetadata, field.TypeJSON, value)
	}
	if wu.mutation.MetadataCleared() {
		_spec.ClearField(workflow.FieldMetadata, field.TypeJSON)
	}
	if wu.mutation.RobotaccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.RobotaccountsTable,
			Columns: []string{workflow.RobotaccountsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(robotaccount.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.RemovedRobotaccountsIDs(); len(nodes) > 0 && !wu.mutation.RobotaccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.RobotaccountsTable,
			Columns: []string{workflow.RobotaccountsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(robotaccount.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 := wu.mutation.RobotaccountsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.RobotaccountsTable,
			Columns: []string{workflow.RobotaccountsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(robotaccount.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wu.mutation.WorkflowrunsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.WorkflowrunsTable,
			Columns: []string{workflow.WorkflowrunsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.RemovedWorkflowrunsIDs(); len(nodes) > 0 && !wu.mutation.WorkflowrunsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.WorkflowrunsTable,
			Columns: []string{workflow.WorkflowrunsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.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 := wu.mutation.WorkflowrunsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.WorkflowrunsTable,
			Columns: []string{workflow.WorkflowrunsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wu.mutation.OrganizationCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.OrganizationTable,
			Columns: []string{workflow.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.OrganizationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.OrganizationTable,
			Columns: []string{workflow.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wu.mutation.ContractCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.ContractTable,
			Columns: []string{workflow.ContractColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.ContractIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.ContractTable,
			Columns: []string{workflow.ContractColumn},
			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 wu.mutation.IntegrationAttachmentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   workflow.IntegrationAttachmentsTable,
			Columns: []string{workflow.IntegrationAttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integrationattachment.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.RemovedIntegrationAttachmentsIDs(); len(nodes) > 0 && !wu.mutation.IntegrationAttachmentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   workflow.IntegrationAttachmentsTable,
			Columns: []string{workflow.IntegrationAttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integrationattachment.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 := wu.mutation.IntegrationAttachmentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   workflow.IntegrationAttachmentsTable,
			Columns: []string{workflow.IntegrationAttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integrationattachment.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wu.mutation.ProjectCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.ProjectTable,
			Columns: []string{workflow.ProjectColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.ProjectIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.ProjectTable,
			Columns: []string{workflow.ProjectColumn},
			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 wu.mutation.LatestWorkflowRunCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.LatestWorkflowRunTable,
			Columns: []string{workflow.LatestWorkflowRunColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.LatestWorkflowRunIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.LatestWorkflowRunTable,
			Columns: []string{workflow.LatestWorkflowRunColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wu.mutation.ReferrersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   workflow.ReferrersTable,
			Columns: workflow.ReferrersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(referrer.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.RemovedReferrersIDs(); len(nodes) > 0 && !wu.mutation.ReferrersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   workflow.ReferrersTable,
			Columns: workflow.ReferrersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(referrer.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 := wu.mutation.ReferrersIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   workflow.ReferrersTable,
			Columns: workflow.ReferrersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(referrer.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(wu.modifiers...)
	if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{workflow.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	wu.mutation.done = true
	return n, nil
}

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

// SetProjectOld sets the "project_old" field.
func (wuo *WorkflowUpdateOne) SetProjectOld(s string) *WorkflowUpdateOne {
	wuo.mutation.SetProjectOld(s)
	return wuo
}

// SetNillableProjectOld sets the "project_old" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableProjectOld(s *string) *WorkflowUpdateOne {
	if s != nil {
		wuo.SetProjectOld(*s)
	}
	return wuo
}

// ClearProjectOld clears the value of the "project_old" field.
func (wuo *WorkflowUpdateOne) ClearProjectOld() *WorkflowUpdateOne {
	wuo.mutation.ClearProjectOld()
	return wuo
}

// SetTeam sets the "team" field.
func (wuo *WorkflowUpdateOne) SetTeam(s string) *WorkflowUpdateOne {
	wuo.mutation.SetTeam(s)
	return wuo
}

// SetNillableTeam sets the "team" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableTeam(s *string) *WorkflowUpdateOne {
	if s != nil {
		wuo.SetTeam(*s)
	}
	return wuo
}

// ClearTeam clears the value of the "team" field.
func (wuo *WorkflowUpdateOne) ClearTeam() *WorkflowUpdateOne {
	wuo.mutation.ClearTeam()
	return wuo
}

// SetRunsCount sets the "runs_count" field.
func (wuo *WorkflowUpdateOne) SetRunsCount(i int) *WorkflowUpdateOne {
	wuo.mutation.ResetRunsCount()
	wuo.mutation.SetRunsCount(i)
	return wuo
}

// SetNillableRunsCount sets the "runs_count" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableRunsCount(i *int) *WorkflowUpdateOne {
	if i != nil {
		wuo.SetRunsCount(*i)
	}
	return wuo
}

// AddRunsCount adds i to the "runs_count" field.
func (wuo *WorkflowUpdateOne) AddRunsCount(i int) *WorkflowUpdateOne {
	wuo.mutation.AddRunsCount(i)
	return wuo
}

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

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

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

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

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

// SetPublic sets the "public" field.
func (wuo *WorkflowUpdateOne) SetPublic(b bool) *WorkflowUpdateOne {
	wuo.mutation.SetPublic(b)
	return wuo
}

// SetNillablePublic sets the "public" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillablePublic(b *bool) *WorkflowUpdateOne {
	if b != nil {
		wuo.SetPublic(*b)
	}
	return wuo
}

// SetOrganizationID sets the "organization_id" field.
func (wuo *WorkflowUpdateOne) SetOrganizationID(u uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.SetOrganizationID(u)
	return wuo
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableOrganizationID(u *uuid.UUID) *WorkflowUpdateOne {
	if u != nil {
		wuo.SetOrganizationID(*u)
	}
	return wuo
}

// SetProjectID sets the "project_id" field.
func (wuo *WorkflowUpdateOne) SetProjectID(u uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.SetProjectID(u)
	return wuo
}

// SetNillableProjectID sets the "project_id" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableProjectID(u *uuid.UUID) *WorkflowUpdateOne {
	if u != nil {
		wuo.SetProjectID(*u)
	}
	return wuo
}

// SetLatestRun sets the "latest_run" field.
func (wuo *WorkflowUpdateOne) SetLatestRun(u uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.SetLatestRun(u)
	return wuo
}

// SetNillableLatestRun sets the "latest_run" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableLatestRun(u *uuid.UUID) *WorkflowUpdateOne {
	if u != nil {
		wuo.SetLatestRun(*u)
	}
	return wuo
}

// ClearLatestRun clears the value of the "latest_run" field.
func (wuo *WorkflowUpdateOne) ClearLatestRun() *WorkflowUpdateOne {
	wuo.mutation.ClearLatestRun()
	return wuo
}

// SetDescription sets the "description" field.
func (wuo *WorkflowUpdateOne) SetDescription(s string) *WorkflowUpdateOne {
	wuo.mutation.SetDescription(s)
	return wuo
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableDescription(s *string) *WorkflowUpdateOne {
	if s != nil {
		wuo.SetDescription(*s)
	}
	return wuo
}

// ClearDescription clears the value of the "description" field.
func (wuo *WorkflowUpdateOne) ClearDescription() *WorkflowUpdateOne {
	wuo.mutation.ClearDescription()
	return wuo
}

// SetMetadata sets the "metadata" field.
func (wuo *WorkflowUpdateOne) SetMetadata(m map[string]interface{}) *WorkflowUpdateOne {
	wuo.mutation.SetMetadata(m)
	return wuo
}

// ClearMetadata clears the value of the "metadata" field.
func (wuo *WorkflowUpdateOne) ClearMetadata() *WorkflowUpdateOne {
	wuo.mutation.ClearMetadata()
	return wuo
}

// AddRobotaccountIDs adds the "robotaccounts" edge to the RobotAccount entity by IDs.
func (wuo *WorkflowUpdateOne) AddRobotaccountIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.AddRobotaccountIDs(ids...)
	return wuo
}

// AddRobotaccounts adds the "robotaccounts" edges to the RobotAccount entity.
func (wuo *WorkflowUpdateOne) AddRobotaccounts(r ...*RobotAccount) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wuo.AddRobotaccountIDs(ids...)
}

// AddWorkflowrunIDs adds the "workflowruns" edge to the WorkflowRun entity by IDs.
func (wuo *WorkflowUpdateOne) AddWorkflowrunIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.AddWorkflowrunIDs(ids...)
	return wuo
}

// AddWorkflowruns adds the "workflowruns" edges to the WorkflowRun entity.
func (wuo *WorkflowUpdateOne) AddWorkflowruns(w ...*WorkflowRun) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return wuo.AddWorkflowrunIDs(ids...)
}

// SetOrganization sets the "organization" edge to the Organization entity.
func (wuo *WorkflowUpdateOne) SetOrganization(o *Organization) *WorkflowUpdateOne {
	return wuo.SetOrganizationID(o.ID)
}

// SetContractID sets the "contract" edge to the WorkflowContract entity by ID.
func (wuo *WorkflowUpdateOne) SetContractID(id uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.SetContractID(id)
	return wuo
}

// SetContract sets the "contract" edge to the WorkflowContract entity.
func (wuo *WorkflowUpdateOne) SetContract(w *WorkflowContract) *WorkflowUpdateOne {
	return wuo.SetContractID(w.ID)
}

// AddIntegrationAttachmentIDs adds the "integration_attachments" edge to the IntegrationAttachment entity by IDs.
func (wuo *WorkflowUpdateOne) AddIntegrationAttachmentIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.AddIntegrationAttachmentIDs(ids...)
	return wuo
}

// AddIntegrationAttachments adds the "integration_attachments" edges to the IntegrationAttachment entity.
func (wuo *WorkflowUpdateOne) AddIntegrationAttachments(i ...*IntegrationAttachment) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return wuo.AddIntegrationAttachmentIDs(ids...)
}

// SetProject sets the "project" edge to the Project entity.
func (wuo *WorkflowUpdateOne) SetProject(p *Project) *WorkflowUpdateOne {
	return wuo.SetProjectID(p.ID)
}

// SetLatestWorkflowRunID sets the "latest_workflow_run" edge to the WorkflowRun entity by ID.
func (wuo *WorkflowUpdateOne) SetLatestWorkflowRunID(id uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.SetLatestWorkflowRunID(id)
	return wuo
}

// SetNillableLatestWorkflowRunID sets the "latest_workflow_run" edge to the WorkflowRun entity by ID if the given value is not nil.
func (wuo *WorkflowUpdateOne) SetNillableLatestWorkflowRunID(id *uuid.UUID) *WorkflowUpdateOne {
	if id != nil {
		wuo = wuo.SetLatestWorkflowRunID(*id)
	}
	return wuo
}

// SetLatestWorkflowRun sets the "latest_workflow_run" edge to the WorkflowRun entity.
func (wuo *WorkflowUpdateOne) SetLatestWorkflowRun(w *WorkflowRun) *WorkflowUpdateOne {
	return wuo.SetLatestWorkflowRunID(w.ID)
}

// AddReferrerIDs adds the "referrers" edge to the Referrer entity by IDs.
func (wuo *WorkflowUpdateOne) AddReferrerIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.AddReferrerIDs(ids...)
	return wuo
}

// AddReferrers adds the "referrers" edges to the Referrer entity.
func (wuo *WorkflowUpdateOne) AddReferrers(r ...*Referrer) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wuo.AddReferrerIDs(ids...)
}

// Mutation returns the WorkflowMutation object of the builder.
func (wuo *WorkflowUpdateOne) Mutation() *WorkflowMutation {
	return wuo.mutation
}

// ClearRobotaccounts clears all "robotaccounts" edges to the RobotAccount entity.
func (wuo *WorkflowUpdateOne) ClearRobotaccounts() *WorkflowUpdateOne {
	wuo.mutation.ClearRobotaccounts()
	return wuo
}

// RemoveRobotaccountIDs removes the "robotaccounts" edge to RobotAccount entities by IDs.
func (wuo *WorkflowUpdateOne) RemoveRobotaccountIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.RemoveRobotaccountIDs(ids...)
	return wuo
}

// RemoveRobotaccounts removes "robotaccounts" edges to RobotAccount entities.
func (wuo *WorkflowUpdateOne) RemoveRobotaccounts(r ...*RobotAccount) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wuo.RemoveRobotaccountIDs(ids...)
}

// ClearWorkflowruns clears all "workflowruns" edges to the WorkflowRun entity.
func (wuo *WorkflowUpdateOne) ClearWorkflowruns() *WorkflowUpdateOne {
	wuo.mutation.ClearWorkflowruns()
	return wuo
}

// RemoveWorkflowrunIDs removes the "workflowruns" edge to WorkflowRun entities by IDs.
func (wuo *WorkflowUpdateOne) RemoveWorkflowrunIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.RemoveWorkflowrunIDs(ids...)
	return wuo
}

// RemoveWorkflowruns removes "workflowruns" edges to WorkflowRun entities.
func (wuo *WorkflowUpdateOne) RemoveWorkflowruns(w ...*WorkflowRun) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(w))
	for i := range w {
		ids[i] = w[i].ID
	}
	return wuo.RemoveWorkflowrunIDs(ids...)
}

// ClearOrganization clears the "organization" edge to the Organization entity.
func (wuo *WorkflowUpdateOne) ClearOrganization() *WorkflowUpdateOne {
	wuo.mutation.ClearOrganization()
	return wuo
}

// ClearContract clears the "contract" edge to the WorkflowContract entity.
func (wuo *WorkflowUpdateOne) ClearContract() *WorkflowUpdateOne {
	wuo.mutation.ClearContract()
	return wuo
}

// ClearIntegrationAttachments clears all "integration_attachments" edges to the IntegrationAttachment entity.
func (wuo *WorkflowUpdateOne) ClearIntegrationAttachments() *WorkflowUpdateOne {
	wuo.mutation.ClearIntegrationAttachments()
	return wuo
}

// RemoveIntegrationAttachmentIDs removes the "integration_attachments" edge to IntegrationAttachment entities by IDs.
func (wuo *WorkflowUpdateOne) RemoveIntegrationAttachmentIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.RemoveIntegrationAttachmentIDs(ids...)
	return wuo
}

// RemoveIntegrationAttachments removes "integration_attachments" edges to IntegrationAttachment entities.
func (wuo *WorkflowUpdateOne) RemoveIntegrationAttachments(i ...*IntegrationAttachment) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(i))
	for j := range i {
		ids[j] = i[j].ID
	}
	return wuo.RemoveIntegrationAttachmentIDs(ids...)
}

// ClearProject clears the "project" edge to the Project entity.
func (wuo *WorkflowUpdateOne) ClearProject() *WorkflowUpdateOne {
	wuo.mutation.ClearProject()
	return wuo
}

// ClearLatestWorkflowRun clears the "latest_workflow_run" edge to the WorkflowRun entity.
func (wuo *WorkflowUpdateOne) ClearLatestWorkflowRun() *WorkflowUpdateOne {
	wuo.mutation.ClearLatestWorkflowRun()
	return wuo
}

// ClearReferrers clears all "referrers" edges to the Referrer entity.
func (wuo *WorkflowUpdateOne) ClearReferrers() *WorkflowUpdateOne {
	wuo.mutation.ClearReferrers()
	return wuo
}

// RemoveReferrerIDs removes the "referrers" edge to Referrer entities by IDs.
func (wuo *WorkflowUpdateOne) RemoveReferrerIDs(ids ...uuid.UUID) *WorkflowUpdateOne {
	wuo.mutation.RemoveReferrerIDs(ids...)
	return wuo
}

// RemoveReferrers removes "referrers" edges to Referrer entities.
func (wuo *WorkflowUpdateOne) RemoveReferrers(r ...*Referrer) *WorkflowUpdateOne {
	ids := make([]uuid.UUID, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return wuo.RemoveReferrerIDs(ids...)
}

// Where appends a list predicates to the WorkflowUpdate builder.
func (wuo *WorkflowUpdateOne) Where(ps ...predicate.Workflow) *WorkflowUpdateOne {
	wuo.mutation.Where(ps...)
	return wuo
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (wuo *WorkflowUpdateOne) check() error {
	if wuo.mutation.OrganizationCleared() && len(wuo.mutation.OrganizationIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "Workflow.organization"`)
	}
	if wuo.mutation.ContractCleared() && len(wuo.mutation.ContractIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "Workflow.contract"`)
	}
	if wuo.mutation.ProjectCleared() && len(wuo.mutation.ProjectIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "Workflow.project"`)
	}
	return nil
}

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

func (wuo *WorkflowUpdateOne) sqlSave(ctx context.Context) (_node *Workflow, err error) {
	if err := wuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(workflow.Table, workflow.Columns, sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID))
	id, ok := wuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Workflow.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := wuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, workflow.FieldID)
		for _, f := range fields {
			if !workflow.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != workflow.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := wuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wuo.mutation.ProjectOld(); ok {
		_spec.SetField(workflow.FieldProjectOld, field.TypeString, value)
	}
	if wuo.mutation.ProjectOldCleared() {
		_spec.ClearField(workflow.FieldProjectOld, field.TypeString)
	}
	if value, ok := wuo.mutation.Team(); ok {
		_spec.SetField(workflow.FieldTeam, field.TypeString, value)
	}
	if wuo.mutation.TeamCleared() {
		_spec.ClearField(workflow.FieldTeam, field.TypeString)
	}
	if value, ok := wuo.mutation.RunsCount(); ok {
		_spec.SetField(workflow.FieldRunsCount, field.TypeInt, value)
	}
	if value, ok := wuo.mutation.AddedRunsCount(); ok {
		_spec.AddField(workflow.FieldRunsCount, field.TypeInt, value)
	}
	if value, ok := wuo.mutation.UpdatedAt(); ok {
		_spec.SetField(workflow.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := wuo.mutation.DeletedAt(); ok {
		_spec.SetField(workflow.FieldDeletedAt, field.TypeTime, value)
	}
	if wuo.mutation.DeletedAtCleared() {
		_spec.ClearField(workflow.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := wuo.mutation.Public(); ok {
		_spec.SetField(workflow.FieldPublic, field.TypeBool, value)
	}
	if value, ok := wuo.mutation.Description(); ok {
		_spec.SetField(workflow.FieldDescription, field.TypeString, value)
	}
	if wuo.mutation.DescriptionCleared() {
		_spec.ClearField(workflow.FieldDescription, field.TypeString)
	}
	if value, ok := wuo.mutation.Metadata(); ok {
		_spec.SetField(workflow.FieldMetadata, field.TypeJSON, value)
	}
	if wuo.mutation.MetadataCleared() {
		_spec.ClearField(workflow.FieldMetadata, field.TypeJSON)
	}
	if wuo.mutation.RobotaccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.RobotaccountsTable,
			Columns: []string{workflow.RobotaccountsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(robotaccount.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.RemovedRobotaccountsIDs(); len(nodes) > 0 && !wuo.mutation.RobotaccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.RobotaccountsTable,
			Columns: []string{workflow.RobotaccountsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(robotaccount.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 := wuo.mutation.RobotaccountsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.RobotaccountsTable,
			Columns: []string{workflow.RobotaccountsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(robotaccount.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wuo.mutation.WorkflowrunsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.WorkflowrunsTable,
			Columns: []string{workflow.WorkflowrunsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.RemovedWorkflowrunsIDs(); len(nodes) > 0 && !wuo.mutation.WorkflowrunsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.WorkflowrunsTable,
			Columns: []string{workflow.WorkflowrunsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.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 := wuo.mutation.WorkflowrunsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   workflow.WorkflowrunsTable,
			Columns: []string{workflow.WorkflowrunsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wuo.mutation.OrganizationCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.OrganizationTable,
			Columns: []string{workflow.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.OrganizationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.OrganizationTable,
			Columns: []string{workflow.OrganizationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(organization.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wuo.mutation.ContractCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.ContractTable,
			Columns: []string{workflow.ContractColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontract.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.ContractIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.ContractTable,
			Columns: []string{workflow.ContractColumn},
			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 wuo.mutation.IntegrationAttachmentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   workflow.IntegrationAttachmentsTable,
			Columns: []string{workflow.IntegrationAttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integrationattachment.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.RemovedIntegrationAttachmentsIDs(); len(nodes) > 0 && !wuo.mutation.IntegrationAttachmentsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   workflow.IntegrationAttachmentsTable,
			Columns: []string{workflow.IntegrationAttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integrationattachment.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 := wuo.mutation.IntegrationAttachmentsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   workflow.IntegrationAttachmentsTable,
			Columns: []string{workflow.IntegrationAttachmentsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(integrationattachment.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wuo.mutation.ProjectCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.ProjectTable,
			Columns: []string{workflow.ProjectColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(project.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.ProjectIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflow.ProjectTable,
			Columns: []string{workflow.ProjectColumn},
			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 wuo.mutation.LatestWorkflowRunCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.LatestWorkflowRunTable,
			Columns: []string{workflow.LatestWorkflowRunColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.LatestWorkflowRunIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflow.LatestWorkflowRunTable,
			Columns: []string{workflow.LatestWorkflowRunColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wuo.mutation.ReferrersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   workflow.ReferrersTable,
			Columns: workflow.ReferrersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(referrer.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.RemovedReferrersIDs(); len(nodes) > 0 && !wuo.mutation.ReferrersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   workflow.ReferrersTable,
			Columns: workflow.ReferrersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(referrer.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 := wuo.mutation.ReferrersIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   workflow.ReferrersTable,
			Columns: workflow.ReferrersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(referrer.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(wuo.modifiers...)
	_node = &Workflow{config: wuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{workflow.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	wuo.mutation.done = true
	return _node, nil
}
