// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/buildbarn/bb-portal/ent/gen/ent/artifactmetrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/filesmetric"
	"github.com/buildbarn/bb-portal/ent/gen/ent/metrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
)

// ArtifactMetricsUpdate is the builder for updating ArtifactMetrics entities.
type ArtifactMetricsUpdate struct {
	config
	hooks    []Hook
	mutation *ArtifactMetricsMutation
}

// Where appends a list predicates to the ArtifactMetricsUpdate builder.
func (amu *ArtifactMetricsUpdate) Where(ps ...predicate.ArtifactMetrics) *ArtifactMetricsUpdate {
	amu.mutation.Where(ps...)
	return amu
}

// SetMetricsID sets the "metrics" edge to the Metrics entity by ID.
func (amu *ArtifactMetricsUpdate) SetMetricsID(id int) *ArtifactMetricsUpdate {
	amu.mutation.SetMetricsID(id)
	return amu
}

// SetNillableMetricsID sets the "metrics" edge to the Metrics entity by ID if the given value is not nil.
func (amu *ArtifactMetricsUpdate) SetNillableMetricsID(id *int) *ArtifactMetricsUpdate {
	if id != nil {
		amu = amu.SetMetricsID(*id)
	}
	return amu
}

// SetMetrics sets the "metrics" edge to the Metrics entity.
func (amu *ArtifactMetricsUpdate) SetMetrics(m *Metrics) *ArtifactMetricsUpdate {
	return amu.SetMetricsID(m.ID)
}

// SetSourceArtifactsReadID sets the "source_artifacts_read" edge to the FilesMetric entity by ID.
func (amu *ArtifactMetricsUpdate) SetSourceArtifactsReadID(id int) *ArtifactMetricsUpdate {
	amu.mutation.SetSourceArtifactsReadID(id)
	return amu
}

// SetNillableSourceArtifactsReadID sets the "source_artifacts_read" edge to the FilesMetric entity by ID if the given value is not nil.
func (amu *ArtifactMetricsUpdate) SetNillableSourceArtifactsReadID(id *int) *ArtifactMetricsUpdate {
	if id != nil {
		amu = amu.SetSourceArtifactsReadID(*id)
	}
	return amu
}

// SetSourceArtifactsRead sets the "source_artifacts_read" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) SetSourceArtifactsRead(f *FilesMetric) *ArtifactMetricsUpdate {
	return amu.SetSourceArtifactsReadID(f.ID)
}

// SetOutputArtifactsSeenID sets the "output_artifacts_seen" edge to the FilesMetric entity by ID.
func (amu *ArtifactMetricsUpdate) SetOutputArtifactsSeenID(id int) *ArtifactMetricsUpdate {
	amu.mutation.SetOutputArtifactsSeenID(id)
	return amu
}

// SetNillableOutputArtifactsSeenID sets the "output_artifacts_seen" edge to the FilesMetric entity by ID if the given value is not nil.
func (amu *ArtifactMetricsUpdate) SetNillableOutputArtifactsSeenID(id *int) *ArtifactMetricsUpdate {
	if id != nil {
		amu = amu.SetOutputArtifactsSeenID(*id)
	}
	return amu
}

// SetOutputArtifactsSeen sets the "output_artifacts_seen" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) SetOutputArtifactsSeen(f *FilesMetric) *ArtifactMetricsUpdate {
	return amu.SetOutputArtifactsSeenID(f.ID)
}

// SetOutputArtifactsFromActionCacheID sets the "output_artifacts_from_action_cache" edge to the FilesMetric entity by ID.
func (amu *ArtifactMetricsUpdate) SetOutputArtifactsFromActionCacheID(id int) *ArtifactMetricsUpdate {
	amu.mutation.SetOutputArtifactsFromActionCacheID(id)
	return amu
}

// SetNillableOutputArtifactsFromActionCacheID sets the "output_artifacts_from_action_cache" edge to the FilesMetric entity by ID if the given value is not nil.
func (amu *ArtifactMetricsUpdate) SetNillableOutputArtifactsFromActionCacheID(id *int) *ArtifactMetricsUpdate {
	if id != nil {
		amu = amu.SetOutputArtifactsFromActionCacheID(*id)
	}
	return amu
}

// SetOutputArtifactsFromActionCache sets the "output_artifacts_from_action_cache" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) SetOutputArtifactsFromActionCache(f *FilesMetric) *ArtifactMetricsUpdate {
	return amu.SetOutputArtifactsFromActionCacheID(f.ID)
}

// SetTopLevelArtifactsID sets the "top_level_artifacts" edge to the FilesMetric entity by ID.
func (amu *ArtifactMetricsUpdate) SetTopLevelArtifactsID(id int) *ArtifactMetricsUpdate {
	amu.mutation.SetTopLevelArtifactsID(id)
	return amu
}

// SetNillableTopLevelArtifactsID sets the "top_level_artifacts" edge to the FilesMetric entity by ID if the given value is not nil.
func (amu *ArtifactMetricsUpdate) SetNillableTopLevelArtifactsID(id *int) *ArtifactMetricsUpdate {
	if id != nil {
		amu = amu.SetTopLevelArtifactsID(*id)
	}
	return amu
}

// SetTopLevelArtifacts sets the "top_level_artifacts" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) SetTopLevelArtifacts(f *FilesMetric) *ArtifactMetricsUpdate {
	return amu.SetTopLevelArtifactsID(f.ID)
}

// Mutation returns the ArtifactMetricsMutation object of the builder.
func (amu *ArtifactMetricsUpdate) Mutation() *ArtifactMetricsMutation {
	return amu.mutation
}

// ClearMetrics clears the "metrics" edge to the Metrics entity.
func (amu *ArtifactMetricsUpdate) ClearMetrics() *ArtifactMetricsUpdate {
	amu.mutation.ClearMetrics()
	return amu
}

// ClearSourceArtifactsRead clears the "source_artifacts_read" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) ClearSourceArtifactsRead() *ArtifactMetricsUpdate {
	amu.mutation.ClearSourceArtifactsRead()
	return amu
}

// ClearOutputArtifactsSeen clears the "output_artifacts_seen" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) ClearOutputArtifactsSeen() *ArtifactMetricsUpdate {
	amu.mutation.ClearOutputArtifactsSeen()
	return amu
}

// ClearOutputArtifactsFromActionCache clears the "output_artifacts_from_action_cache" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) ClearOutputArtifactsFromActionCache() *ArtifactMetricsUpdate {
	amu.mutation.ClearOutputArtifactsFromActionCache()
	return amu
}

// ClearTopLevelArtifacts clears the "top_level_artifacts" edge to the FilesMetric entity.
func (amu *ArtifactMetricsUpdate) ClearTopLevelArtifacts() *ArtifactMetricsUpdate {
	amu.mutation.ClearTopLevelArtifacts()
	return amu
}

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

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

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

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

func (amu *ArtifactMetricsUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(artifactmetrics.Table, artifactmetrics.Columns, sqlgraph.NewFieldSpec(artifactmetrics.FieldID, field.TypeInt))
	if ps := amu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if amu.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   artifactmetrics.MetricsTable,
			Columns: []string{artifactmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amu.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   artifactmetrics.MetricsTable,
			Columns: []string{artifactmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amu.mutation.SourceArtifactsReadCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.SourceArtifactsReadTable,
			Columns: []string{artifactmetrics.SourceArtifactsReadColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amu.mutation.SourceArtifactsReadIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.SourceArtifactsReadTable,
			Columns: []string{artifactmetrics.SourceArtifactsReadColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amu.mutation.OutputArtifactsSeenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsSeenTable,
			Columns: []string{artifactmetrics.OutputArtifactsSeenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amu.mutation.OutputArtifactsSeenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsSeenTable,
			Columns: []string{artifactmetrics.OutputArtifactsSeenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amu.mutation.OutputArtifactsFromActionCacheCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsFromActionCacheTable,
			Columns: []string{artifactmetrics.OutputArtifactsFromActionCacheColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amu.mutation.OutputArtifactsFromActionCacheIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsFromActionCacheTable,
			Columns: []string{artifactmetrics.OutputArtifactsFromActionCacheColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amu.mutation.TopLevelArtifactsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   artifactmetrics.TopLevelArtifactsTable,
			Columns: []string{artifactmetrics.TopLevelArtifactsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amu.mutation.TopLevelArtifactsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   artifactmetrics.TopLevelArtifactsTable,
			Columns: []string{artifactmetrics.TopLevelArtifactsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, amu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{artifactmetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	amu.mutation.done = true
	return n, nil
}

// ArtifactMetricsUpdateOne is the builder for updating a single ArtifactMetrics entity.
type ArtifactMetricsUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ArtifactMetricsMutation
}

// SetMetricsID sets the "metrics" edge to the Metrics entity by ID.
func (amuo *ArtifactMetricsUpdateOne) SetMetricsID(id int) *ArtifactMetricsUpdateOne {
	amuo.mutation.SetMetricsID(id)
	return amuo
}

// SetNillableMetricsID sets the "metrics" edge to the Metrics entity by ID if the given value is not nil.
func (amuo *ArtifactMetricsUpdateOne) SetNillableMetricsID(id *int) *ArtifactMetricsUpdateOne {
	if id != nil {
		amuo = amuo.SetMetricsID(*id)
	}
	return amuo
}

// SetMetrics sets the "metrics" edge to the Metrics entity.
func (amuo *ArtifactMetricsUpdateOne) SetMetrics(m *Metrics) *ArtifactMetricsUpdateOne {
	return amuo.SetMetricsID(m.ID)
}

// SetSourceArtifactsReadID sets the "source_artifacts_read" edge to the FilesMetric entity by ID.
func (amuo *ArtifactMetricsUpdateOne) SetSourceArtifactsReadID(id int) *ArtifactMetricsUpdateOne {
	amuo.mutation.SetSourceArtifactsReadID(id)
	return amuo
}

// SetNillableSourceArtifactsReadID sets the "source_artifacts_read" edge to the FilesMetric entity by ID if the given value is not nil.
func (amuo *ArtifactMetricsUpdateOne) SetNillableSourceArtifactsReadID(id *int) *ArtifactMetricsUpdateOne {
	if id != nil {
		amuo = amuo.SetSourceArtifactsReadID(*id)
	}
	return amuo
}

// SetSourceArtifactsRead sets the "source_artifacts_read" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) SetSourceArtifactsRead(f *FilesMetric) *ArtifactMetricsUpdateOne {
	return amuo.SetSourceArtifactsReadID(f.ID)
}

// SetOutputArtifactsSeenID sets the "output_artifacts_seen" edge to the FilesMetric entity by ID.
func (amuo *ArtifactMetricsUpdateOne) SetOutputArtifactsSeenID(id int) *ArtifactMetricsUpdateOne {
	amuo.mutation.SetOutputArtifactsSeenID(id)
	return amuo
}

// SetNillableOutputArtifactsSeenID sets the "output_artifacts_seen" edge to the FilesMetric entity by ID if the given value is not nil.
func (amuo *ArtifactMetricsUpdateOne) SetNillableOutputArtifactsSeenID(id *int) *ArtifactMetricsUpdateOne {
	if id != nil {
		amuo = amuo.SetOutputArtifactsSeenID(*id)
	}
	return amuo
}

// SetOutputArtifactsSeen sets the "output_artifacts_seen" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) SetOutputArtifactsSeen(f *FilesMetric) *ArtifactMetricsUpdateOne {
	return amuo.SetOutputArtifactsSeenID(f.ID)
}

// SetOutputArtifactsFromActionCacheID sets the "output_artifacts_from_action_cache" edge to the FilesMetric entity by ID.
func (amuo *ArtifactMetricsUpdateOne) SetOutputArtifactsFromActionCacheID(id int) *ArtifactMetricsUpdateOne {
	amuo.mutation.SetOutputArtifactsFromActionCacheID(id)
	return amuo
}

// SetNillableOutputArtifactsFromActionCacheID sets the "output_artifacts_from_action_cache" edge to the FilesMetric entity by ID if the given value is not nil.
func (amuo *ArtifactMetricsUpdateOne) SetNillableOutputArtifactsFromActionCacheID(id *int) *ArtifactMetricsUpdateOne {
	if id != nil {
		amuo = amuo.SetOutputArtifactsFromActionCacheID(*id)
	}
	return amuo
}

// SetOutputArtifactsFromActionCache sets the "output_artifacts_from_action_cache" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) SetOutputArtifactsFromActionCache(f *FilesMetric) *ArtifactMetricsUpdateOne {
	return amuo.SetOutputArtifactsFromActionCacheID(f.ID)
}

// SetTopLevelArtifactsID sets the "top_level_artifacts" edge to the FilesMetric entity by ID.
func (amuo *ArtifactMetricsUpdateOne) SetTopLevelArtifactsID(id int) *ArtifactMetricsUpdateOne {
	amuo.mutation.SetTopLevelArtifactsID(id)
	return amuo
}

// SetNillableTopLevelArtifactsID sets the "top_level_artifacts" edge to the FilesMetric entity by ID if the given value is not nil.
func (amuo *ArtifactMetricsUpdateOne) SetNillableTopLevelArtifactsID(id *int) *ArtifactMetricsUpdateOne {
	if id != nil {
		amuo = amuo.SetTopLevelArtifactsID(*id)
	}
	return amuo
}

// SetTopLevelArtifacts sets the "top_level_artifacts" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) SetTopLevelArtifacts(f *FilesMetric) *ArtifactMetricsUpdateOne {
	return amuo.SetTopLevelArtifactsID(f.ID)
}

// Mutation returns the ArtifactMetricsMutation object of the builder.
func (amuo *ArtifactMetricsUpdateOne) Mutation() *ArtifactMetricsMutation {
	return amuo.mutation
}

// ClearMetrics clears the "metrics" edge to the Metrics entity.
func (amuo *ArtifactMetricsUpdateOne) ClearMetrics() *ArtifactMetricsUpdateOne {
	amuo.mutation.ClearMetrics()
	return amuo
}

// ClearSourceArtifactsRead clears the "source_artifacts_read" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) ClearSourceArtifactsRead() *ArtifactMetricsUpdateOne {
	amuo.mutation.ClearSourceArtifactsRead()
	return amuo
}

// ClearOutputArtifactsSeen clears the "output_artifacts_seen" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) ClearOutputArtifactsSeen() *ArtifactMetricsUpdateOne {
	amuo.mutation.ClearOutputArtifactsSeen()
	return amuo
}

// ClearOutputArtifactsFromActionCache clears the "output_artifacts_from_action_cache" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) ClearOutputArtifactsFromActionCache() *ArtifactMetricsUpdateOne {
	amuo.mutation.ClearOutputArtifactsFromActionCache()
	return amuo
}

// ClearTopLevelArtifacts clears the "top_level_artifacts" edge to the FilesMetric entity.
func (amuo *ArtifactMetricsUpdateOne) ClearTopLevelArtifacts() *ArtifactMetricsUpdateOne {
	amuo.mutation.ClearTopLevelArtifacts()
	return amuo
}

// Where appends a list predicates to the ArtifactMetricsUpdate builder.
func (amuo *ArtifactMetricsUpdateOne) Where(ps ...predicate.ArtifactMetrics) *ArtifactMetricsUpdateOne {
	amuo.mutation.Where(ps...)
	return amuo
}

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

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

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

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

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

func (amuo *ArtifactMetricsUpdateOne) sqlSave(ctx context.Context) (_node *ArtifactMetrics, err error) {
	_spec := sqlgraph.NewUpdateSpec(artifactmetrics.Table, artifactmetrics.Columns, sqlgraph.NewFieldSpec(artifactmetrics.FieldID, field.TypeInt))
	id, ok := amuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ArtifactMetrics.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := amuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, artifactmetrics.FieldID)
		for _, f := range fields {
			if !artifactmetrics.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != artifactmetrics.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := amuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if amuo.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   artifactmetrics.MetricsTable,
			Columns: []string{artifactmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amuo.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   artifactmetrics.MetricsTable,
			Columns: []string{artifactmetrics.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amuo.mutation.SourceArtifactsReadCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.SourceArtifactsReadTable,
			Columns: []string{artifactmetrics.SourceArtifactsReadColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amuo.mutation.SourceArtifactsReadIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.SourceArtifactsReadTable,
			Columns: []string{artifactmetrics.SourceArtifactsReadColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amuo.mutation.OutputArtifactsSeenCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsSeenTable,
			Columns: []string{artifactmetrics.OutputArtifactsSeenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amuo.mutation.OutputArtifactsSeenIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsSeenTable,
			Columns: []string{artifactmetrics.OutputArtifactsSeenColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amuo.mutation.OutputArtifactsFromActionCacheCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsFromActionCacheTable,
			Columns: []string{artifactmetrics.OutputArtifactsFromActionCacheColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amuo.mutation.OutputArtifactsFromActionCacheIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   artifactmetrics.OutputArtifactsFromActionCacheTable,
			Columns: []string{artifactmetrics.OutputArtifactsFromActionCacheColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if amuo.mutation.TopLevelArtifactsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   artifactmetrics.TopLevelArtifactsTable,
			Columns: []string{artifactmetrics.TopLevelArtifactsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := amuo.mutation.TopLevelArtifactsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   artifactmetrics.TopLevelArtifactsTable,
			Columns: []string{artifactmetrics.TopLevelArtifactsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(filesmetric.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &ArtifactMetrics{config: amuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, amuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{artifactmetrics.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	amuo.mutation.done = true
	return _node, nil
}
