// 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/biz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/attestation"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/casbackend"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/predicate"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/projectversion"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontractversion"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowrun"
	"github.com/google/uuid"
	"github.com/secure-systems-lab/go-securesystemslib/dsse"
)

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

// Where appends a list predicates to the WorkflowRunUpdate builder.
func (wru *WorkflowRunUpdate) Where(ps ...predicate.WorkflowRun) *WorkflowRunUpdate {
	wru.mutation.Where(ps...)
	return wru
}

// SetFinishedAt sets the "finished_at" field.
func (wru *WorkflowRunUpdate) SetFinishedAt(t time.Time) *WorkflowRunUpdate {
	wru.mutation.SetFinishedAt(t)
	return wru
}

// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableFinishedAt(t *time.Time) *WorkflowRunUpdate {
	if t != nil {
		wru.SetFinishedAt(*t)
	}
	return wru
}

// ClearFinishedAt clears the value of the "finished_at" field.
func (wru *WorkflowRunUpdate) ClearFinishedAt() *WorkflowRunUpdate {
	wru.mutation.ClearFinishedAt()
	return wru
}

// SetState sets the "state" field.
func (wru *WorkflowRunUpdate) SetState(brs biz.WorkflowRunStatus) *WorkflowRunUpdate {
	wru.mutation.SetState(brs)
	return wru
}

// SetNillableState sets the "state" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableState(brs *biz.WorkflowRunStatus) *WorkflowRunUpdate {
	if brs != nil {
		wru.SetState(*brs)
	}
	return wru
}

// SetReason sets the "reason" field.
func (wru *WorkflowRunUpdate) SetReason(s string) *WorkflowRunUpdate {
	wru.mutation.SetReason(s)
	return wru
}

// SetNillableReason sets the "reason" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableReason(s *string) *WorkflowRunUpdate {
	if s != nil {
		wru.SetReason(*s)
	}
	return wru
}

// ClearReason clears the value of the "reason" field.
func (wru *WorkflowRunUpdate) ClearReason() *WorkflowRunUpdate {
	wru.mutation.ClearReason()
	return wru
}

// SetRunURL sets the "run_url" field.
func (wru *WorkflowRunUpdate) SetRunURL(s string) *WorkflowRunUpdate {
	wru.mutation.SetRunURL(s)
	return wru
}

// SetNillableRunURL sets the "run_url" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableRunURL(s *string) *WorkflowRunUpdate {
	if s != nil {
		wru.SetRunURL(*s)
	}
	return wru
}

// ClearRunURL clears the value of the "run_url" field.
func (wru *WorkflowRunUpdate) ClearRunURL() *WorkflowRunUpdate {
	wru.mutation.ClearRunURL()
	return wru
}

// SetRunnerType sets the "runner_type" field.
func (wru *WorkflowRunUpdate) SetRunnerType(s string) *WorkflowRunUpdate {
	wru.mutation.SetRunnerType(s)
	return wru
}

// SetNillableRunnerType sets the "runner_type" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableRunnerType(s *string) *WorkflowRunUpdate {
	if s != nil {
		wru.SetRunnerType(*s)
	}
	return wru
}

// ClearRunnerType clears the value of the "runner_type" field.
func (wru *WorkflowRunUpdate) ClearRunnerType() *WorkflowRunUpdate {
	wru.mutation.ClearRunnerType()
	return wru
}

// SetAttestation sets the "attestation" field.
func (wru *WorkflowRunUpdate) SetAttestation(d *dsse.Envelope) *WorkflowRunUpdate {
	wru.mutation.SetAttestation(d)
	return wru
}

// ClearAttestation clears the value of the "attestation" field.
func (wru *WorkflowRunUpdate) ClearAttestation() *WorkflowRunUpdate {
	wru.mutation.ClearAttestation()
	return wru
}

// SetAttestationDigest sets the "attestation_digest" field.
func (wru *WorkflowRunUpdate) SetAttestationDigest(s string) *WorkflowRunUpdate {
	wru.mutation.SetAttestationDigest(s)
	return wru
}

// SetNillableAttestationDigest sets the "attestation_digest" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableAttestationDigest(s *string) *WorkflowRunUpdate {
	if s != nil {
		wru.SetAttestationDigest(*s)
	}
	return wru
}

// ClearAttestationDigest clears the value of the "attestation_digest" field.
func (wru *WorkflowRunUpdate) ClearAttestationDigest() *WorkflowRunUpdate {
	wru.mutation.ClearAttestationDigest()
	return wru
}

// SetAttestationState sets the "attestation_state" field.
func (wru *WorkflowRunUpdate) SetAttestationState(b []byte) *WorkflowRunUpdate {
	wru.mutation.SetAttestationState(b)
	return wru
}

// ClearAttestationState clears the value of the "attestation_state" field.
func (wru *WorkflowRunUpdate) ClearAttestationState() *WorkflowRunUpdate {
	wru.mutation.ClearAttestationState()
	return wru
}

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (wru *WorkflowRunUpdate) SetContractRevisionUsed(i int) *WorkflowRunUpdate {
	wru.mutation.ResetContractRevisionUsed()
	wru.mutation.SetContractRevisionUsed(i)
	return wru
}

// SetNillableContractRevisionUsed sets the "contract_revision_used" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableContractRevisionUsed(i *int) *WorkflowRunUpdate {
	if i != nil {
		wru.SetContractRevisionUsed(*i)
	}
	return wru
}

// AddContractRevisionUsed adds i to the "contract_revision_used" field.
func (wru *WorkflowRunUpdate) AddContractRevisionUsed(i int) *WorkflowRunUpdate {
	wru.mutation.AddContractRevisionUsed(i)
	return wru
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (wru *WorkflowRunUpdate) SetContractRevisionLatest(i int) *WorkflowRunUpdate {
	wru.mutation.ResetContractRevisionLatest()
	wru.mutation.SetContractRevisionLatest(i)
	return wru
}

// SetNillableContractRevisionLatest sets the "contract_revision_latest" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableContractRevisionLatest(i *int) *WorkflowRunUpdate {
	if i != nil {
		wru.SetContractRevisionLatest(*i)
	}
	return wru
}

// AddContractRevisionLatest adds i to the "contract_revision_latest" field.
func (wru *WorkflowRunUpdate) AddContractRevisionLatest(i int) *WorkflowRunUpdate {
	wru.mutation.AddContractRevisionLatest(i)
	return wru
}

// SetVersionID sets the "version_id" field.
func (wru *WorkflowRunUpdate) SetVersionID(u uuid.UUID) *WorkflowRunUpdate {
	wru.mutation.SetVersionID(u)
	return wru
}

// SetNillableVersionID sets the "version_id" field if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableVersionID(u *uuid.UUID) *WorkflowRunUpdate {
	if u != nil {
		wru.SetVersionID(*u)
	}
	return wru
}

// SetContractVersionID sets the "contract_version" edge to the WorkflowContractVersion entity by ID.
func (wru *WorkflowRunUpdate) SetContractVersionID(id uuid.UUID) *WorkflowRunUpdate {
	wru.mutation.SetContractVersionID(id)
	return wru
}

// SetNillableContractVersionID sets the "contract_version" edge to the WorkflowContractVersion entity by ID if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableContractVersionID(id *uuid.UUID) *WorkflowRunUpdate {
	if id != nil {
		wru = wru.SetContractVersionID(*id)
	}
	return wru
}

// SetContractVersion sets the "contract_version" edge to the WorkflowContractVersion entity.
func (wru *WorkflowRunUpdate) SetContractVersion(w *WorkflowContractVersion) *WorkflowRunUpdate {
	return wru.SetContractVersionID(w.ID)
}

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

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

// SetVersion sets the "version" edge to the ProjectVersion entity.
func (wru *WorkflowRunUpdate) SetVersion(p *ProjectVersion) *WorkflowRunUpdate {
	return wru.SetVersionID(p.ID)
}

// SetAttestationBundleID sets the "attestation_bundle" edge to the Attestation entity by ID.
func (wru *WorkflowRunUpdate) SetAttestationBundleID(id uuid.UUID) *WorkflowRunUpdate {
	wru.mutation.SetAttestationBundleID(id)
	return wru
}

// SetNillableAttestationBundleID sets the "attestation_bundle" edge to the Attestation entity by ID if the given value is not nil.
func (wru *WorkflowRunUpdate) SetNillableAttestationBundleID(id *uuid.UUID) *WorkflowRunUpdate {
	if id != nil {
		wru = wru.SetAttestationBundleID(*id)
	}
	return wru
}

// SetAttestationBundle sets the "attestation_bundle" edge to the Attestation entity.
func (wru *WorkflowRunUpdate) SetAttestationBundle(a *Attestation) *WorkflowRunUpdate {
	return wru.SetAttestationBundleID(a.ID)
}

// Mutation returns the WorkflowRunMutation object of the builder.
func (wru *WorkflowRunUpdate) Mutation() *WorkflowRunMutation {
	return wru.mutation
}

// ClearContractVersion clears the "contract_version" edge to the WorkflowContractVersion entity.
func (wru *WorkflowRunUpdate) ClearContractVersion() *WorkflowRunUpdate {
	wru.mutation.ClearContractVersion()
	return wru
}

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

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

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

// ClearVersion clears the "version" edge to the ProjectVersion entity.
func (wru *WorkflowRunUpdate) ClearVersion() *WorkflowRunUpdate {
	wru.mutation.ClearVersion()
	return wru
}

// ClearAttestationBundle clears the "attestation_bundle" edge to the Attestation entity.
func (wru *WorkflowRunUpdate) ClearAttestationBundle() *WorkflowRunUpdate {
	wru.mutation.ClearAttestationBundle()
	return wru
}

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (wru *WorkflowRunUpdate) check() error {
	if v, ok := wru.mutation.State(); ok {
		if err := workflowrun.StateValidator(v); err != nil {
			return &ValidationError{Name: "state", err: fmt.Errorf(`ent: validator failed for field "WorkflowRun.state": %w`, err)}
		}
	}
	if wru.mutation.WorkflowCleared() && len(wru.mutation.WorkflowIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "WorkflowRun.workflow"`)
	}
	if wru.mutation.VersionCleared() && len(wru.mutation.VersionIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "WorkflowRun.version"`)
	}
	return nil
}

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

func (wru *WorkflowRunUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := wru.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(workflowrun.Table, workflowrun.Columns, sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID))
	if ps := wru.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wru.mutation.FinishedAt(); ok {
		_spec.SetField(workflowrun.FieldFinishedAt, field.TypeTime, value)
	}
	if wru.mutation.FinishedAtCleared() {
		_spec.ClearField(workflowrun.FieldFinishedAt, field.TypeTime)
	}
	if value, ok := wru.mutation.State(); ok {
		_spec.SetField(workflowrun.FieldState, field.TypeEnum, value)
	}
	if value, ok := wru.mutation.Reason(); ok {
		_spec.SetField(workflowrun.FieldReason, field.TypeString, value)
	}
	if wru.mutation.ReasonCleared() {
		_spec.ClearField(workflowrun.FieldReason, field.TypeString)
	}
	if value, ok := wru.mutation.RunURL(); ok {
		_spec.SetField(workflowrun.FieldRunURL, field.TypeString, value)
	}
	if wru.mutation.RunURLCleared() {
		_spec.ClearField(workflowrun.FieldRunURL, field.TypeString)
	}
	if value, ok := wru.mutation.RunnerType(); ok {
		_spec.SetField(workflowrun.FieldRunnerType, field.TypeString, value)
	}
	if wru.mutation.RunnerTypeCleared() {
		_spec.ClearField(workflowrun.FieldRunnerType, field.TypeString)
	}
	if value, ok := wru.mutation.Attestation(); ok {
		_spec.SetField(workflowrun.FieldAttestation, field.TypeJSON, value)
	}
	if wru.mutation.AttestationCleared() {
		_spec.ClearField(workflowrun.FieldAttestation, field.TypeJSON)
	}
	if value, ok := wru.mutation.AttestationDigest(); ok {
		_spec.SetField(workflowrun.FieldAttestationDigest, field.TypeString, value)
	}
	if wru.mutation.AttestationDigestCleared() {
		_spec.ClearField(workflowrun.FieldAttestationDigest, field.TypeString)
	}
	if value, ok := wru.mutation.AttestationState(); ok {
		_spec.SetField(workflowrun.FieldAttestationState, field.TypeBytes, value)
	}
	if wru.mutation.AttestationStateCleared() {
		_spec.ClearField(workflowrun.FieldAttestationState, field.TypeBytes)
	}
	if value, ok := wru.mutation.ContractRevisionUsed(); ok {
		_spec.SetField(workflowrun.FieldContractRevisionUsed, field.TypeInt, value)
	}
	if value, ok := wru.mutation.AddedContractRevisionUsed(); ok {
		_spec.AddField(workflowrun.FieldContractRevisionUsed, field.TypeInt, value)
	}
	if value, ok := wru.mutation.ContractRevisionLatest(); ok {
		_spec.SetField(workflowrun.FieldContractRevisionLatest, field.TypeInt, value)
	}
	if value, ok := wru.mutation.AddedContractRevisionLatest(); ok {
		_spec.AddField(workflowrun.FieldContractRevisionLatest, field.TypeInt, value)
	}
	if wru.mutation.ContractVersionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflowrun.ContractVersionTable,
			Columns: []string{workflowrun.ContractVersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontractversion.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wru.mutation.ContractVersionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflowrun.ContractVersionTable,
			Columns: []string{workflowrun.ContractVersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontractversion.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wru.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   workflowrun.CasBackendsTable,
			Columns: workflowrun.CasBackendsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wru.mutation.RemovedCasBackendsIDs(); len(nodes) > 0 && !wru.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   workflowrun.CasBackendsTable,
			Columns: workflowrun.CasBackendsPrimaryKey,
			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 := wru.mutation.CasBackendsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   workflowrun.CasBackendsTable,
			Columns: workflowrun.CasBackendsPrimaryKey,
			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 wru.mutation.VersionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflowrun.VersionTable,
			Columns: []string{workflowrun.VersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(projectversion.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wru.mutation.VersionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflowrun.VersionTable,
			Columns: []string{workflowrun.VersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(projectversion.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wru.mutation.AttestationBundleCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   workflowrun.AttestationBundleTable,
			Columns: []string{workflowrun.AttestationBundleColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestation.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wru.mutation.AttestationBundleIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   workflowrun.AttestationBundleTable,
			Columns: []string{workflowrun.AttestationBundleColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestation.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(wru.modifiers...)
	if n, err = sqlgraph.UpdateNodes(ctx, wru.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{workflowrun.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	wru.mutation.done = true
	return n, nil
}

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

// SetFinishedAt sets the "finished_at" field.
func (wruo *WorkflowRunUpdateOne) SetFinishedAt(t time.Time) *WorkflowRunUpdateOne {
	wruo.mutation.SetFinishedAt(t)
	return wruo
}

// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableFinishedAt(t *time.Time) *WorkflowRunUpdateOne {
	if t != nil {
		wruo.SetFinishedAt(*t)
	}
	return wruo
}

// ClearFinishedAt clears the value of the "finished_at" field.
func (wruo *WorkflowRunUpdateOne) ClearFinishedAt() *WorkflowRunUpdateOne {
	wruo.mutation.ClearFinishedAt()
	return wruo
}

// SetState sets the "state" field.
func (wruo *WorkflowRunUpdateOne) SetState(brs biz.WorkflowRunStatus) *WorkflowRunUpdateOne {
	wruo.mutation.SetState(brs)
	return wruo
}

// SetNillableState sets the "state" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableState(brs *biz.WorkflowRunStatus) *WorkflowRunUpdateOne {
	if brs != nil {
		wruo.SetState(*brs)
	}
	return wruo
}

// SetReason sets the "reason" field.
func (wruo *WorkflowRunUpdateOne) SetReason(s string) *WorkflowRunUpdateOne {
	wruo.mutation.SetReason(s)
	return wruo
}

// SetNillableReason sets the "reason" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableReason(s *string) *WorkflowRunUpdateOne {
	if s != nil {
		wruo.SetReason(*s)
	}
	return wruo
}

// ClearReason clears the value of the "reason" field.
func (wruo *WorkflowRunUpdateOne) ClearReason() *WorkflowRunUpdateOne {
	wruo.mutation.ClearReason()
	return wruo
}

// SetRunURL sets the "run_url" field.
func (wruo *WorkflowRunUpdateOne) SetRunURL(s string) *WorkflowRunUpdateOne {
	wruo.mutation.SetRunURL(s)
	return wruo
}

// SetNillableRunURL sets the "run_url" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableRunURL(s *string) *WorkflowRunUpdateOne {
	if s != nil {
		wruo.SetRunURL(*s)
	}
	return wruo
}

// ClearRunURL clears the value of the "run_url" field.
func (wruo *WorkflowRunUpdateOne) ClearRunURL() *WorkflowRunUpdateOne {
	wruo.mutation.ClearRunURL()
	return wruo
}

// SetRunnerType sets the "runner_type" field.
func (wruo *WorkflowRunUpdateOne) SetRunnerType(s string) *WorkflowRunUpdateOne {
	wruo.mutation.SetRunnerType(s)
	return wruo
}

// SetNillableRunnerType sets the "runner_type" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableRunnerType(s *string) *WorkflowRunUpdateOne {
	if s != nil {
		wruo.SetRunnerType(*s)
	}
	return wruo
}

// ClearRunnerType clears the value of the "runner_type" field.
func (wruo *WorkflowRunUpdateOne) ClearRunnerType() *WorkflowRunUpdateOne {
	wruo.mutation.ClearRunnerType()
	return wruo
}

// SetAttestation sets the "attestation" field.
func (wruo *WorkflowRunUpdateOne) SetAttestation(d *dsse.Envelope) *WorkflowRunUpdateOne {
	wruo.mutation.SetAttestation(d)
	return wruo
}

// ClearAttestation clears the value of the "attestation" field.
func (wruo *WorkflowRunUpdateOne) ClearAttestation() *WorkflowRunUpdateOne {
	wruo.mutation.ClearAttestation()
	return wruo
}

// SetAttestationDigest sets the "attestation_digest" field.
func (wruo *WorkflowRunUpdateOne) SetAttestationDigest(s string) *WorkflowRunUpdateOne {
	wruo.mutation.SetAttestationDigest(s)
	return wruo
}

// SetNillableAttestationDigest sets the "attestation_digest" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableAttestationDigest(s *string) *WorkflowRunUpdateOne {
	if s != nil {
		wruo.SetAttestationDigest(*s)
	}
	return wruo
}

// ClearAttestationDigest clears the value of the "attestation_digest" field.
func (wruo *WorkflowRunUpdateOne) ClearAttestationDigest() *WorkflowRunUpdateOne {
	wruo.mutation.ClearAttestationDigest()
	return wruo
}

// SetAttestationState sets the "attestation_state" field.
func (wruo *WorkflowRunUpdateOne) SetAttestationState(b []byte) *WorkflowRunUpdateOne {
	wruo.mutation.SetAttestationState(b)
	return wruo
}

// ClearAttestationState clears the value of the "attestation_state" field.
func (wruo *WorkflowRunUpdateOne) ClearAttestationState() *WorkflowRunUpdateOne {
	wruo.mutation.ClearAttestationState()
	return wruo
}

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (wruo *WorkflowRunUpdateOne) SetContractRevisionUsed(i int) *WorkflowRunUpdateOne {
	wruo.mutation.ResetContractRevisionUsed()
	wruo.mutation.SetContractRevisionUsed(i)
	return wruo
}

// SetNillableContractRevisionUsed sets the "contract_revision_used" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableContractRevisionUsed(i *int) *WorkflowRunUpdateOne {
	if i != nil {
		wruo.SetContractRevisionUsed(*i)
	}
	return wruo
}

// AddContractRevisionUsed adds i to the "contract_revision_used" field.
func (wruo *WorkflowRunUpdateOne) AddContractRevisionUsed(i int) *WorkflowRunUpdateOne {
	wruo.mutation.AddContractRevisionUsed(i)
	return wruo
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (wruo *WorkflowRunUpdateOne) SetContractRevisionLatest(i int) *WorkflowRunUpdateOne {
	wruo.mutation.ResetContractRevisionLatest()
	wruo.mutation.SetContractRevisionLatest(i)
	return wruo
}

// SetNillableContractRevisionLatest sets the "contract_revision_latest" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableContractRevisionLatest(i *int) *WorkflowRunUpdateOne {
	if i != nil {
		wruo.SetContractRevisionLatest(*i)
	}
	return wruo
}

// AddContractRevisionLatest adds i to the "contract_revision_latest" field.
func (wruo *WorkflowRunUpdateOne) AddContractRevisionLatest(i int) *WorkflowRunUpdateOne {
	wruo.mutation.AddContractRevisionLatest(i)
	return wruo
}

// SetVersionID sets the "version_id" field.
func (wruo *WorkflowRunUpdateOne) SetVersionID(u uuid.UUID) *WorkflowRunUpdateOne {
	wruo.mutation.SetVersionID(u)
	return wruo
}

// SetNillableVersionID sets the "version_id" field if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableVersionID(u *uuid.UUID) *WorkflowRunUpdateOne {
	if u != nil {
		wruo.SetVersionID(*u)
	}
	return wruo
}

// SetContractVersionID sets the "contract_version" edge to the WorkflowContractVersion entity by ID.
func (wruo *WorkflowRunUpdateOne) SetContractVersionID(id uuid.UUID) *WorkflowRunUpdateOne {
	wruo.mutation.SetContractVersionID(id)
	return wruo
}

// SetNillableContractVersionID sets the "contract_version" edge to the WorkflowContractVersion entity by ID if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableContractVersionID(id *uuid.UUID) *WorkflowRunUpdateOne {
	if id != nil {
		wruo = wruo.SetContractVersionID(*id)
	}
	return wruo
}

// SetContractVersion sets the "contract_version" edge to the WorkflowContractVersion entity.
func (wruo *WorkflowRunUpdateOne) SetContractVersion(w *WorkflowContractVersion) *WorkflowRunUpdateOne {
	return wruo.SetContractVersionID(w.ID)
}

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

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

// SetVersion sets the "version" edge to the ProjectVersion entity.
func (wruo *WorkflowRunUpdateOne) SetVersion(p *ProjectVersion) *WorkflowRunUpdateOne {
	return wruo.SetVersionID(p.ID)
}

// SetAttestationBundleID sets the "attestation_bundle" edge to the Attestation entity by ID.
func (wruo *WorkflowRunUpdateOne) SetAttestationBundleID(id uuid.UUID) *WorkflowRunUpdateOne {
	wruo.mutation.SetAttestationBundleID(id)
	return wruo
}

// SetNillableAttestationBundleID sets the "attestation_bundle" edge to the Attestation entity by ID if the given value is not nil.
func (wruo *WorkflowRunUpdateOne) SetNillableAttestationBundleID(id *uuid.UUID) *WorkflowRunUpdateOne {
	if id != nil {
		wruo = wruo.SetAttestationBundleID(*id)
	}
	return wruo
}

// SetAttestationBundle sets the "attestation_bundle" edge to the Attestation entity.
func (wruo *WorkflowRunUpdateOne) SetAttestationBundle(a *Attestation) *WorkflowRunUpdateOne {
	return wruo.SetAttestationBundleID(a.ID)
}

// Mutation returns the WorkflowRunMutation object of the builder.
func (wruo *WorkflowRunUpdateOne) Mutation() *WorkflowRunMutation {
	return wruo.mutation
}

// ClearContractVersion clears the "contract_version" edge to the WorkflowContractVersion entity.
func (wruo *WorkflowRunUpdateOne) ClearContractVersion() *WorkflowRunUpdateOne {
	wruo.mutation.ClearContractVersion()
	return wruo
}

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

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

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

// ClearVersion clears the "version" edge to the ProjectVersion entity.
func (wruo *WorkflowRunUpdateOne) ClearVersion() *WorkflowRunUpdateOne {
	wruo.mutation.ClearVersion()
	return wruo
}

// ClearAttestationBundle clears the "attestation_bundle" edge to the Attestation entity.
func (wruo *WorkflowRunUpdateOne) ClearAttestationBundle() *WorkflowRunUpdateOne {
	wruo.mutation.ClearAttestationBundle()
	return wruo
}

// Where appends a list predicates to the WorkflowRunUpdate builder.
func (wruo *WorkflowRunUpdateOne) Where(ps ...predicate.WorkflowRun) *WorkflowRunUpdateOne {
	wruo.mutation.Where(ps...)
	return wruo
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (wruo *WorkflowRunUpdateOne) check() error {
	if v, ok := wruo.mutation.State(); ok {
		if err := workflowrun.StateValidator(v); err != nil {
			return &ValidationError{Name: "state", err: fmt.Errorf(`ent: validator failed for field "WorkflowRun.state": %w`, err)}
		}
	}
	if wruo.mutation.WorkflowCleared() && len(wruo.mutation.WorkflowIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "WorkflowRun.workflow"`)
	}
	if wruo.mutation.VersionCleared() && len(wruo.mutation.VersionIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "WorkflowRun.version"`)
	}
	return nil
}

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

func (wruo *WorkflowRunUpdateOne) sqlSave(ctx context.Context) (_node *WorkflowRun, err error) {
	if err := wruo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(workflowrun.Table, workflowrun.Columns, sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID))
	id, ok := wruo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WorkflowRun.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := wruo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, workflowrun.FieldID)
		for _, f := range fields {
			if !workflowrun.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != workflowrun.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := wruo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wruo.mutation.FinishedAt(); ok {
		_spec.SetField(workflowrun.FieldFinishedAt, field.TypeTime, value)
	}
	if wruo.mutation.FinishedAtCleared() {
		_spec.ClearField(workflowrun.FieldFinishedAt, field.TypeTime)
	}
	if value, ok := wruo.mutation.State(); ok {
		_spec.SetField(workflowrun.FieldState, field.TypeEnum, value)
	}
	if value, ok := wruo.mutation.Reason(); ok {
		_spec.SetField(workflowrun.FieldReason, field.TypeString, value)
	}
	if wruo.mutation.ReasonCleared() {
		_spec.ClearField(workflowrun.FieldReason, field.TypeString)
	}
	if value, ok := wruo.mutation.RunURL(); ok {
		_spec.SetField(workflowrun.FieldRunURL, field.TypeString, value)
	}
	if wruo.mutation.RunURLCleared() {
		_spec.ClearField(workflowrun.FieldRunURL, field.TypeString)
	}
	if value, ok := wruo.mutation.RunnerType(); ok {
		_spec.SetField(workflowrun.FieldRunnerType, field.TypeString, value)
	}
	if wruo.mutation.RunnerTypeCleared() {
		_spec.ClearField(workflowrun.FieldRunnerType, field.TypeString)
	}
	if value, ok := wruo.mutation.Attestation(); ok {
		_spec.SetField(workflowrun.FieldAttestation, field.TypeJSON, value)
	}
	if wruo.mutation.AttestationCleared() {
		_spec.ClearField(workflowrun.FieldAttestation, field.TypeJSON)
	}
	if value, ok := wruo.mutation.AttestationDigest(); ok {
		_spec.SetField(workflowrun.FieldAttestationDigest, field.TypeString, value)
	}
	if wruo.mutation.AttestationDigestCleared() {
		_spec.ClearField(workflowrun.FieldAttestationDigest, field.TypeString)
	}
	if value, ok := wruo.mutation.AttestationState(); ok {
		_spec.SetField(workflowrun.FieldAttestationState, field.TypeBytes, value)
	}
	if wruo.mutation.AttestationStateCleared() {
		_spec.ClearField(workflowrun.FieldAttestationState, field.TypeBytes)
	}
	if value, ok := wruo.mutation.ContractRevisionUsed(); ok {
		_spec.SetField(workflowrun.FieldContractRevisionUsed, field.TypeInt, value)
	}
	if value, ok := wruo.mutation.AddedContractRevisionUsed(); ok {
		_spec.AddField(workflowrun.FieldContractRevisionUsed, field.TypeInt, value)
	}
	if value, ok := wruo.mutation.ContractRevisionLatest(); ok {
		_spec.SetField(workflowrun.FieldContractRevisionLatest, field.TypeInt, value)
	}
	if value, ok := wruo.mutation.AddedContractRevisionLatest(); ok {
		_spec.AddField(workflowrun.FieldContractRevisionLatest, field.TypeInt, value)
	}
	if wruo.mutation.ContractVersionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflowrun.ContractVersionTable,
			Columns: []string{workflowrun.ContractVersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontractversion.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wruo.mutation.ContractVersionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   workflowrun.ContractVersionTable,
			Columns: []string{workflowrun.ContractVersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflowcontractversion.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wruo.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   workflowrun.CasBackendsTable,
			Columns: workflowrun.CasBackendsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(casbackend.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wruo.mutation.RemovedCasBackendsIDs(); len(nodes) > 0 && !wruo.mutation.CasBackendsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   workflowrun.CasBackendsTable,
			Columns: workflowrun.CasBackendsPrimaryKey,
			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 := wruo.mutation.CasBackendsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   workflowrun.CasBackendsTable,
			Columns: workflowrun.CasBackendsPrimaryKey,
			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 wruo.mutation.VersionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflowrun.VersionTable,
			Columns: []string{workflowrun.VersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(projectversion.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wruo.mutation.VersionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflowrun.VersionTable,
			Columns: []string{workflowrun.VersionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(projectversion.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wruo.mutation.AttestationBundleCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   workflowrun.AttestationBundleTable,
			Columns: []string{workflowrun.AttestationBundleColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestation.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wruo.mutation.AttestationBundleIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   workflowrun.AttestationBundleTable,
			Columns: []string{workflowrun.AttestationBundleColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(attestation.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(wruo.modifiers...)
	_node = &WorkflowRun{config: wruo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, wruo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{workflowrun.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	wruo.mutation.done = true
	return _node, nil
}
