// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect"
	"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/projectversion"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflow"
	"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"
)

// WorkflowRunCreate is the builder for creating a WorkflowRun entity.
type WorkflowRunCreate struct {
	config
	mutation *WorkflowRunMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (wrc *WorkflowRunCreate) SetCreatedAt(t time.Time) *WorkflowRunCreate {
	wrc.mutation.SetCreatedAt(t)
	return wrc
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (wrc *WorkflowRunCreate) SetNillableCreatedAt(t *time.Time) *WorkflowRunCreate {
	if t != nil {
		wrc.SetCreatedAt(*t)
	}
	return wrc
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (wrc *WorkflowRunCreate) SetContractRevisionUsed(i int) *WorkflowRunCreate {
	wrc.mutation.SetContractRevisionUsed(i)
	return wrc
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (wrc *WorkflowRunCreate) SetContractRevisionLatest(i int) *WorkflowRunCreate {
	wrc.mutation.SetContractRevisionLatest(i)
	return wrc
}

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

// SetWorkflowID sets the "workflow_id" field.
func (wrc *WorkflowRunCreate) SetWorkflowID(u uuid.UUID) *WorkflowRunCreate {
	wrc.mutation.SetWorkflowID(u)
	return wrc
}

// SetID sets the "id" field.
func (wrc *WorkflowRunCreate) SetID(u uuid.UUID) *WorkflowRunCreate {
	wrc.mutation.SetID(u)
	return wrc
}

// SetNillableID sets the "id" field if the given value is not nil.
func (wrc *WorkflowRunCreate) SetNillableID(u *uuid.UUID) *WorkflowRunCreate {
	if u != nil {
		wrc.SetID(*u)
	}
	return wrc
}

// SetWorkflow sets the "workflow" edge to the Workflow entity.
func (wrc *WorkflowRunCreate) SetWorkflow(w *Workflow) *WorkflowRunCreate {
	return wrc.SetWorkflowID(w.ID)
}

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

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

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

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

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

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

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

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

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

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

// Save creates the WorkflowRun in the database.
func (wrc *WorkflowRunCreate) Save(ctx context.Context) (*WorkflowRun, error) {
	wrc.defaults()
	return withHooks(ctx, wrc.sqlSave, wrc.mutation, wrc.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (wrc *WorkflowRunCreate) SaveX(ctx context.Context) *WorkflowRun {
	v, err := wrc.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// defaults sets the default values of the builder before save.
func (wrc *WorkflowRunCreate) defaults() {
	if _, ok := wrc.mutation.CreatedAt(); !ok {
		v := workflowrun.DefaultCreatedAt()
		wrc.mutation.SetCreatedAt(v)
	}
	if _, ok := wrc.mutation.State(); !ok {
		v := workflowrun.DefaultState
		wrc.mutation.SetState(v)
	}
	if _, ok := wrc.mutation.ID(); !ok {
		v := workflowrun.DefaultID()
		wrc.mutation.SetID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (wrc *WorkflowRunCreate) check() error {
	if _, ok := wrc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WorkflowRun.created_at"`)}
	}
	if _, ok := wrc.mutation.State(); !ok {
		return &ValidationError{Name: "state", err: errors.New(`ent: missing required field "WorkflowRun.state"`)}
	}
	if v, ok := wrc.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 _, ok := wrc.mutation.ContractRevisionUsed(); !ok {
		return &ValidationError{Name: "contract_revision_used", err: errors.New(`ent: missing required field "WorkflowRun.contract_revision_used"`)}
	}
	if _, ok := wrc.mutation.ContractRevisionLatest(); !ok {
		return &ValidationError{Name: "contract_revision_latest", err: errors.New(`ent: missing required field "WorkflowRun.contract_revision_latest"`)}
	}
	if _, ok := wrc.mutation.VersionID(); !ok {
		return &ValidationError{Name: "version_id", err: errors.New(`ent: missing required field "WorkflowRun.version_id"`)}
	}
	if _, ok := wrc.mutation.WorkflowID(); !ok {
		return &ValidationError{Name: "workflow_id", err: errors.New(`ent: missing required field "WorkflowRun.workflow_id"`)}
	}
	if len(wrc.mutation.WorkflowIDs()) == 0 {
		return &ValidationError{Name: "workflow", err: errors.New(`ent: missing required edge "WorkflowRun.workflow"`)}
	}
	if len(wrc.mutation.VersionIDs()) == 0 {
		return &ValidationError{Name: "version", err: errors.New(`ent: missing required edge "WorkflowRun.version"`)}
	}
	return nil
}

func (wrc *WorkflowRunCreate) sqlSave(ctx context.Context) (*WorkflowRun, error) {
	if err := wrc.check(); err != nil {
		return nil, err
	}
	_node, _spec := wrc.createSpec()
	if err := sqlgraph.CreateNode(ctx, wrc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != nil {
		if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
			_node.ID = *id
		} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
			return nil, err
		}
	}
	wrc.mutation.id = &_node.ID
	wrc.mutation.done = true
	return _node, nil
}

func (wrc *WorkflowRunCreate) createSpec() (*WorkflowRun, *sqlgraph.CreateSpec) {
	var (
		_node = &WorkflowRun{config: wrc.config}
		_spec = sqlgraph.NewCreateSpec(workflowrun.Table, sqlgraph.NewFieldSpec(workflowrun.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = wrc.conflict
	if id, ok := wrc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := wrc.mutation.CreatedAt(); ok {
		_spec.SetField(workflowrun.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := wrc.mutation.FinishedAt(); ok {
		_spec.SetField(workflowrun.FieldFinishedAt, field.TypeTime, value)
		_node.FinishedAt = value
	}
	if value, ok := wrc.mutation.State(); ok {
		_spec.SetField(workflowrun.FieldState, field.TypeEnum, value)
		_node.State = value
	}
	if value, ok := wrc.mutation.Reason(); ok {
		_spec.SetField(workflowrun.FieldReason, field.TypeString, value)
		_node.Reason = value
	}
	if value, ok := wrc.mutation.RunURL(); ok {
		_spec.SetField(workflowrun.FieldRunURL, field.TypeString, value)
		_node.RunURL = value
	}
	if value, ok := wrc.mutation.RunnerType(); ok {
		_spec.SetField(workflowrun.FieldRunnerType, field.TypeString, value)
		_node.RunnerType = value
	}
	if value, ok := wrc.mutation.Attestation(); ok {
		_spec.SetField(workflowrun.FieldAttestation, field.TypeJSON, value)
		_node.Attestation = value
	}
	if value, ok := wrc.mutation.AttestationDigest(); ok {
		_spec.SetField(workflowrun.FieldAttestationDigest, field.TypeString, value)
		_node.AttestationDigest = value
	}
	if value, ok := wrc.mutation.AttestationState(); ok {
		_spec.SetField(workflowrun.FieldAttestationState, field.TypeBytes, value)
		_node.AttestationState = value
	}
	if value, ok := wrc.mutation.ContractRevisionUsed(); ok {
		_spec.SetField(workflowrun.FieldContractRevisionUsed, field.TypeInt, value)
		_node.ContractRevisionUsed = value
	}
	if value, ok := wrc.mutation.ContractRevisionLatest(); ok {
		_spec.SetField(workflowrun.FieldContractRevisionLatest, field.TypeInt, value)
		_node.ContractRevisionLatest = value
	}
	if nodes := wrc.mutation.WorkflowIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   workflowrun.WorkflowTable,
			Columns: []string{workflowrun.WorkflowColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(workflow.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.WorkflowID = nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := wrc.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)
		}
		_node.workflow_run_contract_version = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := wrc.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 = append(_spec.Edges, edge)
	}
	if nodes := wrc.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)
		}
		_node.VersionID = nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := wrc.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 = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WorkflowRun.Create().
//		SetCreatedAt(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.WorkflowRunUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (wrc *WorkflowRunCreate) OnConflict(opts ...sql.ConflictOption) *WorkflowRunUpsertOne {
	wrc.conflict = opts
	return &WorkflowRunUpsertOne{
		create: wrc,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.WorkflowRun.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (wrc *WorkflowRunCreate) OnConflictColumns(columns ...string) *WorkflowRunUpsertOne {
	wrc.conflict = append(wrc.conflict, sql.ConflictColumns(columns...))
	return &WorkflowRunUpsertOne{
		create: wrc,
	}
}

type (
	// WorkflowRunUpsertOne is the builder for "upsert"-ing
	//  one WorkflowRun node.
	WorkflowRunUpsertOne struct {
		create *WorkflowRunCreate
	}

	// WorkflowRunUpsert is the "OnConflict" setter.
	WorkflowRunUpsert struct {
		*sql.UpdateSet
	}
)

// SetFinishedAt sets the "finished_at" field.
func (u *WorkflowRunUpsert) SetFinishedAt(v time.Time) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldFinishedAt, v)
	return u
}

// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateFinishedAt() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldFinishedAt)
	return u
}

// ClearFinishedAt clears the value of the "finished_at" field.
func (u *WorkflowRunUpsert) ClearFinishedAt() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldFinishedAt)
	return u
}

// SetState sets the "state" field.
func (u *WorkflowRunUpsert) SetState(v biz.WorkflowRunStatus) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldState, v)
	return u
}

// UpdateState sets the "state" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateState() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldState)
	return u
}

// SetReason sets the "reason" field.
func (u *WorkflowRunUpsert) SetReason(v string) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldReason, v)
	return u
}

// UpdateReason sets the "reason" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateReason() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldReason)
	return u
}

// ClearReason clears the value of the "reason" field.
func (u *WorkflowRunUpsert) ClearReason() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldReason)
	return u
}

// SetRunURL sets the "run_url" field.
func (u *WorkflowRunUpsert) SetRunURL(v string) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldRunURL, v)
	return u
}

// UpdateRunURL sets the "run_url" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateRunURL() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldRunURL)
	return u
}

// ClearRunURL clears the value of the "run_url" field.
func (u *WorkflowRunUpsert) ClearRunURL() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldRunURL)
	return u
}

// SetRunnerType sets the "runner_type" field.
func (u *WorkflowRunUpsert) SetRunnerType(v string) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldRunnerType, v)
	return u
}

// UpdateRunnerType sets the "runner_type" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateRunnerType() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldRunnerType)
	return u
}

// ClearRunnerType clears the value of the "runner_type" field.
func (u *WorkflowRunUpsert) ClearRunnerType() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldRunnerType)
	return u
}

// SetAttestation sets the "attestation" field.
func (u *WorkflowRunUpsert) SetAttestation(v *dsse.Envelope) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldAttestation, v)
	return u
}

// UpdateAttestation sets the "attestation" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateAttestation() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldAttestation)
	return u
}

// ClearAttestation clears the value of the "attestation" field.
func (u *WorkflowRunUpsert) ClearAttestation() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldAttestation)
	return u
}

// SetAttestationDigest sets the "attestation_digest" field.
func (u *WorkflowRunUpsert) SetAttestationDigest(v string) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldAttestationDigest, v)
	return u
}

// UpdateAttestationDigest sets the "attestation_digest" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateAttestationDigest() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldAttestationDigest)
	return u
}

// ClearAttestationDigest clears the value of the "attestation_digest" field.
func (u *WorkflowRunUpsert) ClearAttestationDigest() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldAttestationDigest)
	return u
}

// SetAttestationState sets the "attestation_state" field.
func (u *WorkflowRunUpsert) SetAttestationState(v []byte) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldAttestationState, v)
	return u
}

// UpdateAttestationState sets the "attestation_state" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateAttestationState() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldAttestationState)
	return u
}

// ClearAttestationState clears the value of the "attestation_state" field.
func (u *WorkflowRunUpsert) ClearAttestationState() *WorkflowRunUpsert {
	u.SetNull(workflowrun.FieldAttestationState)
	return u
}

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (u *WorkflowRunUpsert) SetContractRevisionUsed(v int) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldContractRevisionUsed, v)
	return u
}

// UpdateContractRevisionUsed sets the "contract_revision_used" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateContractRevisionUsed() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldContractRevisionUsed)
	return u
}

// AddContractRevisionUsed adds v to the "contract_revision_used" field.
func (u *WorkflowRunUpsert) AddContractRevisionUsed(v int) *WorkflowRunUpsert {
	u.Add(workflowrun.FieldContractRevisionUsed, v)
	return u
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (u *WorkflowRunUpsert) SetContractRevisionLatest(v int) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldContractRevisionLatest, v)
	return u
}

// UpdateContractRevisionLatest sets the "contract_revision_latest" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateContractRevisionLatest() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldContractRevisionLatest)
	return u
}

// AddContractRevisionLatest adds v to the "contract_revision_latest" field.
func (u *WorkflowRunUpsert) AddContractRevisionLatest(v int) *WorkflowRunUpsert {
	u.Add(workflowrun.FieldContractRevisionLatest, v)
	return u
}

// SetVersionID sets the "version_id" field.
func (u *WorkflowRunUpsert) SetVersionID(v uuid.UUID) *WorkflowRunUpsert {
	u.Set(workflowrun.FieldVersionID, v)
	return u
}

// UpdateVersionID sets the "version_id" field to the value that was provided on create.
func (u *WorkflowRunUpsert) UpdateVersionID() *WorkflowRunUpsert {
	u.SetExcluded(workflowrun.FieldVersionID)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.WorkflowRun.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(workflowrun.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WorkflowRunUpsertOne) UpdateNewValues() *WorkflowRunUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(workflowrun.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(workflowrun.FieldCreatedAt)
		}
		if _, exists := u.create.mutation.WorkflowID(); exists {
			s.SetIgnore(workflowrun.FieldWorkflowID)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.WorkflowRun.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *WorkflowRunUpsertOne) Ignore() *WorkflowRunUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *WorkflowRunUpsertOne) DoNothing() *WorkflowRunUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the WorkflowRunCreate.OnConflict
// documentation for more info.
func (u *WorkflowRunUpsertOne) Update(set func(*WorkflowRunUpsert)) *WorkflowRunUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&WorkflowRunUpsert{UpdateSet: update})
	}))
	return u
}

// SetFinishedAt sets the "finished_at" field.
func (u *WorkflowRunUpsertOne) SetFinishedAt(v time.Time) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetFinishedAt(v)
	})
}

// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateFinishedAt() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateFinishedAt()
	})
}

// ClearFinishedAt clears the value of the "finished_at" field.
func (u *WorkflowRunUpsertOne) ClearFinishedAt() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearFinishedAt()
	})
}

// SetState sets the "state" field.
func (u *WorkflowRunUpsertOne) SetState(v biz.WorkflowRunStatus) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetState(v)
	})
}

// UpdateState sets the "state" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateState() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateState()
	})
}

// SetReason sets the "reason" field.
func (u *WorkflowRunUpsertOne) SetReason(v string) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetReason(v)
	})
}

// UpdateReason sets the "reason" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateReason() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateReason()
	})
}

// ClearReason clears the value of the "reason" field.
func (u *WorkflowRunUpsertOne) ClearReason() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearReason()
	})
}

// SetRunURL sets the "run_url" field.
func (u *WorkflowRunUpsertOne) SetRunURL(v string) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetRunURL(v)
	})
}

// UpdateRunURL sets the "run_url" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateRunURL() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateRunURL()
	})
}

// ClearRunURL clears the value of the "run_url" field.
func (u *WorkflowRunUpsertOne) ClearRunURL() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearRunURL()
	})
}

// SetRunnerType sets the "runner_type" field.
func (u *WorkflowRunUpsertOne) SetRunnerType(v string) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetRunnerType(v)
	})
}

// UpdateRunnerType sets the "runner_type" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateRunnerType() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateRunnerType()
	})
}

// ClearRunnerType clears the value of the "runner_type" field.
func (u *WorkflowRunUpsertOne) ClearRunnerType() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearRunnerType()
	})
}

// SetAttestation sets the "attestation" field.
func (u *WorkflowRunUpsertOne) SetAttestation(v *dsse.Envelope) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetAttestation(v)
	})
}

// UpdateAttestation sets the "attestation" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateAttestation() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateAttestation()
	})
}

// ClearAttestation clears the value of the "attestation" field.
func (u *WorkflowRunUpsertOne) ClearAttestation() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearAttestation()
	})
}

// SetAttestationDigest sets the "attestation_digest" field.
func (u *WorkflowRunUpsertOne) SetAttestationDigest(v string) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetAttestationDigest(v)
	})
}

// UpdateAttestationDigest sets the "attestation_digest" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateAttestationDigest() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateAttestationDigest()
	})
}

// ClearAttestationDigest clears the value of the "attestation_digest" field.
func (u *WorkflowRunUpsertOne) ClearAttestationDigest() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearAttestationDigest()
	})
}

// SetAttestationState sets the "attestation_state" field.
func (u *WorkflowRunUpsertOne) SetAttestationState(v []byte) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetAttestationState(v)
	})
}

// UpdateAttestationState sets the "attestation_state" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateAttestationState() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateAttestationState()
	})
}

// ClearAttestationState clears the value of the "attestation_state" field.
func (u *WorkflowRunUpsertOne) ClearAttestationState() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearAttestationState()
	})
}

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (u *WorkflowRunUpsertOne) SetContractRevisionUsed(v int) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetContractRevisionUsed(v)
	})
}

// AddContractRevisionUsed adds v to the "contract_revision_used" field.
func (u *WorkflowRunUpsertOne) AddContractRevisionUsed(v int) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.AddContractRevisionUsed(v)
	})
}

// UpdateContractRevisionUsed sets the "contract_revision_used" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateContractRevisionUsed() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateContractRevisionUsed()
	})
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (u *WorkflowRunUpsertOne) SetContractRevisionLatest(v int) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetContractRevisionLatest(v)
	})
}

// AddContractRevisionLatest adds v to the "contract_revision_latest" field.
func (u *WorkflowRunUpsertOne) AddContractRevisionLatest(v int) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.AddContractRevisionLatest(v)
	})
}

// UpdateContractRevisionLatest sets the "contract_revision_latest" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateContractRevisionLatest() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateContractRevisionLatest()
	})
}

// SetVersionID sets the "version_id" field.
func (u *WorkflowRunUpsertOne) SetVersionID(v uuid.UUID) *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetVersionID(v)
	})
}

// UpdateVersionID sets the "version_id" field to the value that was provided on create.
func (u *WorkflowRunUpsertOne) UpdateVersionID() *WorkflowRunUpsertOne {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateVersionID()
	})
}

// Exec executes the query.
func (u *WorkflowRunUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for WorkflowRunCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

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

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *WorkflowRunUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
	if u.create.driver.Dialect() == dialect.MySQL {
		// In case of "ON CONFLICT", there is no way to get back non-numeric ID
		// fields from the database since MySQL does not support the RETURNING clause.
		return id, errors.New("ent: WorkflowRunUpsertOne.ID is not supported by MySQL driver. Use WorkflowRunUpsertOne.Exec instead")
	}
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *WorkflowRunUpsertOne) IDX(ctx context.Context) uuid.UUID {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// WorkflowRunCreateBulk is the builder for creating many WorkflowRun entities in bulk.
type WorkflowRunCreateBulk struct {
	config
	err      error
	builders []*WorkflowRunCreate
	conflict []sql.ConflictOption
}

// Save creates the WorkflowRun entities in the database.
func (wrcb *WorkflowRunCreateBulk) Save(ctx context.Context) ([]*WorkflowRun, error) {
	if wrcb.err != nil {
		return nil, wrcb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(wrcb.builders))
	nodes := make([]*WorkflowRun, len(wrcb.builders))
	mutators := make([]Mutator, len(wrcb.builders))
	for i := range wrcb.builders {
		func(i int, root context.Context) {
			builder := wrcb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*WorkflowRunMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, wrcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = wrcb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, wrcb.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, wrcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (wrcb *WorkflowRunCreateBulk) SaveX(ctx context.Context) []*WorkflowRun {
	v, err := wrcb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WorkflowRun.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.WorkflowRunUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (wrcb *WorkflowRunCreateBulk) OnConflict(opts ...sql.ConflictOption) *WorkflowRunUpsertBulk {
	wrcb.conflict = opts
	return &WorkflowRunUpsertBulk{
		create: wrcb,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.WorkflowRun.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (wrcb *WorkflowRunCreateBulk) OnConflictColumns(columns ...string) *WorkflowRunUpsertBulk {
	wrcb.conflict = append(wrcb.conflict, sql.ConflictColumns(columns...))
	return &WorkflowRunUpsertBulk{
		create: wrcb,
	}
}

// WorkflowRunUpsertBulk is the builder for "upsert"-ing
// a bulk of WorkflowRun nodes.
type WorkflowRunUpsertBulk struct {
	create *WorkflowRunCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.WorkflowRun.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(workflowrun.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WorkflowRunUpsertBulk) UpdateNewValues() *WorkflowRunUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(workflowrun.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(workflowrun.FieldCreatedAt)
			}
			if _, exists := b.mutation.WorkflowID(); exists {
				s.SetIgnore(workflowrun.FieldWorkflowID)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.WorkflowRun.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *WorkflowRunUpsertBulk) Ignore() *WorkflowRunUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *WorkflowRunUpsertBulk) DoNothing() *WorkflowRunUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the WorkflowRunCreateBulk.OnConflict
// documentation for more info.
func (u *WorkflowRunUpsertBulk) Update(set func(*WorkflowRunUpsert)) *WorkflowRunUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&WorkflowRunUpsert{UpdateSet: update})
	}))
	return u
}

// SetFinishedAt sets the "finished_at" field.
func (u *WorkflowRunUpsertBulk) SetFinishedAt(v time.Time) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetFinishedAt(v)
	})
}

// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateFinishedAt() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateFinishedAt()
	})
}

// ClearFinishedAt clears the value of the "finished_at" field.
func (u *WorkflowRunUpsertBulk) ClearFinishedAt() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearFinishedAt()
	})
}

// SetState sets the "state" field.
func (u *WorkflowRunUpsertBulk) SetState(v biz.WorkflowRunStatus) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetState(v)
	})
}

// UpdateState sets the "state" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateState() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateState()
	})
}

// SetReason sets the "reason" field.
func (u *WorkflowRunUpsertBulk) SetReason(v string) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetReason(v)
	})
}

// UpdateReason sets the "reason" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateReason() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateReason()
	})
}

// ClearReason clears the value of the "reason" field.
func (u *WorkflowRunUpsertBulk) ClearReason() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearReason()
	})
}

// SetRunURL sets the "run_url" field.
func (u *WorkflowRunUpsertBulk) SetRunURL(v string) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetRunURL(v)
	})
}

// UpdateRunURL sets the "run_url" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateRunURL() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateRunURL()
	})
}

// ClearRunURL clears the value of the "run_url" field.
func (u *WorkflowRunUpsertBulk) ClearRunURL() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearRunURL()
	})
}

// SetRunnerType sets the "runner_type" field.
func (u *WorkflowRunUpsertBulk) SetRunnerType(v string) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetRunnerType(v)
	})
}

// UpdateRunnerType sets the "runner_type" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateRunnerType() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateRunnerType()
	})
}

// ClearRunnerType clears the value of the "runner_type" field.
func (u *WorkflowRunUpsertBulk) ClearRunnerType() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearRunnerType()
	})
}

// SetAttestation sets the "attestation" field.
func (u *WorkflowRunUpsertBulk) SetAttestation(v *dsse.Envelope) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetAttestation(v)
	})
}

// UpdateAttestation sets the "attestation" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateAttestation() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateAttestation()
	})
}

// ClearAttestation clears the value of the "attestation" field.
func (u *WorkflowRunUpsertBulk) ClearAttestation() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearAttestation()
	})
}

// SetAttestationDigest sets the "attestation_digest" field.
func (u *WorkflowRunUpsertBulk) SetAttestationDigest(v string) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetAttestationDigest(v)
	})
}

// UpdateAttestationDigest sets the "attestation_digest" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateAttestationDigest() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateAttestationDigest()
	})
}

// ClearAttestationDigest clears the value of the "attestation_digest" field.
func (u *WorkflowRunUpsertBulk) ClearAttestationDigest() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearAttestationDigest()
	})
}

// SetAttestationState sets the "attestation_state" field.
func (u *WorkflowRunUpsertBulk) SetAttestationState(v []byte) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetAttestationState(v)
	})
}

// UpdateAttestationState sets the "attestation_state" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateAttestationState() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateAttestationState()
	})
}

// ClearAttestationState clears the value of the "attestation_state" field.
func (u *WorkflowRunUpsertBulk) ClearAttestationState() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.ClearAttestationState()
	})
}

// SetContractRevisionUsed sets the "contract_revision_used" field.
func (u *WorkflowRunUpsertBulk) SetContractRevisionUsed(v int) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetContractRevisionUsed(v)
	})
}

// AddContractRevisionUsed adds v to the "contract_revision_used" field.
func (u *WorkflowRunUpsertBulk) AddContractRevisionUsed(v int) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.AddContractRevisionUsed(v)
	})
}

// UpdateContractRevisionUsed sets the "contract_revision_used" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateContractRevisionUsed() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateContractRevisionUsed()
	})
}

// SetContractRevisionLatest sets the "contract_revision_latest" field.
func (u *WorkflowRunUpsertBulk) SetContractRevisionLatest(v int) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetContractRevisionLatest(v)
	})
}

// AddContractRevisionLatest adds v to the "contract_revision_latest" field.
func (u *WorkflowRunUpsertBulk) AddContractRevisionLatest(v int) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.AddContractRevisionLatest(v)
	})
}

// UpdateContractRevisionLatest sets the "contract_revision_latest" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateContractRevisionLatest() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateContractRevisionLatest()
	})
}

// SetVersionID sets the "version_id" field.
func (u *WorkflowRunUpsertBulk) SetVersionID(v uuid.UUID) *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.SetVersionID(v)
	})
}

// UpdateVersionID sets the "version_id" field to the value that was provided on create.
func (u *WorkflowRunUpsertBulk) UpdateVersionID() *WorkflowRunUpsertBulk {
	return u.Update(func(s *WorkflowRunUpsert) {
		s.UpdateVersionID()
	})
}

// Exec executes the query.
func (u *WorkflowRunUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the WorkflowRunCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for WorkflowRunCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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