// 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/actioncachestatistics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/actiondata"
	"github.com/buildbarn/bb-portal/ent/gen/ent/actionsummary"
	"github.com/buildbarn/bb-portal/ent/gen/ent/metrics"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
	"github.com/buildbarn/bb-portal/ent/gen/ent/runnercount"
)

// ActionSummaryUpdate is the builder for updating ActionSummary entities.
type ActionSummaryUpdate struct {
	config
	hooks    []Hook
	mutation *ActionSummaryMutation
}

// Where appends a list predicates to the ActionSummaryUpdate builder.
func (asu *ActionSummaryUpdate) Where(ps ...predicate.ActionSummary) *ActionSummaryUpdate {
	asu.mutation.Where(ps...)
	return asu
}

// SetActionsCreated sets the "actions_created" field.
func (asu *ActionSummaryUpdate) SetActionsCreated(i int64) *ActionSummaryUpdate {
	asu.mutation.ResetActionsCreated()
	asu.mutation.SetActionsCreated(i)
	return asu
}

// SetNillableActionsCreated sets the "actions_created" field if the given value is not nil.
func (asu *ActionSummaryUpdate) SetNillableActionsCreated(i *int64) *ActionSummaryUpdate {
	if i != nil {
		asu.SetActionsCreated(*i)
	}
	return asu
}

// AddActionsCreated adds i to the "actions_created" field.
func (asu *ActionSummaryUpdate) AddActionsCreated(i int64) *ActionSummaryUpdate {
	asu.mutation.AddActionsCreated(i)
	return asu
}

// ClearActionsCreated clears the value of the "actions_created" field.
func (asu *ActionSummaryUpdate) ClearActionsCreated() *ActionSummaryUpdate {
	asu.mutation.ClearActionsCreated()
	return asu
}

// SetActionsCreatedNotIncludingAspects sets the "actions_created_not_including_aspects" field.
func (asu *ActionSummaryUpdate) SetActionsCreatedNotIncludingAspects(i int64) *ActionSummaryUpdate {
	asu.mutation.ResetActionsCreatedNotIncludingAspects()
	asu.mutation.SetActionsCreatedNotIncludingAspects(i)
	return asu
}

// SetNillableActionsCreatedNotIncludingAspects sets the "actions_created_not_including_aspects" field if the given value is not nil.
func (asu *ActionSummaryUpdate) SetNillableActionsCreatedNotIncludingAspects(i *int64) *ActionSummaryUpdate {
	if i != nil {
		asu.SetActionsCreatedNotIncludingAspects(*i)
	}
	return asu
}

// AddActionsCreatedNotIncludingAspects adds i to the "actions_created_not_including_aspects" field.
func (asu *ActionSummaryUpdate) AddActionsCreatedNotIncludingAspects(i int64) *ActionSummaryUpdate {
	asu.mutation.AddActionsCreatedNotIncludingAspects(i)
	return asu
}

// ClearActionsCreatedNotIncludingAspects clears the value of the "actions_created_not_including_aspects" field.
func (asu *ActionSummaryUpdate) ClearActionsCreatedNotIncludingAspects() *ActionSummaryUpdate {
	asu.mutation.ClearActionsCreatedNotIncludingAspects()
	return asu
}

// SetActionsExecuted sets the "actions_executed" field.
func (asu *ActionSummaryUpdate) SetActionsExecuted(i int64) *ActionSummaryUpdate {
	asu.mutation.ResetActionsExecuted()
	asu.mutation.SetActionsExecuted(i)
	return asu
}

// SetNillableActionsExecuted sets the "actions_executed" field if the given value is not nil.
func (asu *ActionSummaryUpdate) SetNillableActionsExecuted(i *int64) *ActionSummaryUpdate {
	if i != nil {
		asu.SetActionsExecuted(*i)
	}
	return asu
}

// AddActionsExecuted adds i to the "actions_executed" field.
func (asu *ActionSummaryUpdate) AddActionsExecuted(i int64) *ActionSummaryUpdate {
	asu.mutation.AddActionsExecuted(i)
	return asu
}

// ClearActionsExecuted clears the value of the "actions_executed" field.
func (asu *ActionSummaryUpdate) ClearActionsExecuted() *ActionSummaryUpdate {
	asu.mutation.ClearActionsExecuted()
	return asu
}

// SetRemoteCacheHits sets the "remote_cache_hits" field.
func (asu *ActionSummaryUpdate) SetRemoteCacheHits(i int64) *ActionSummaryUpdate {
	asu.mutation.ResetRemoteCacheHits()
	asu.mutation.SetRemoteCacheHits(i)
	return asu
}

// SetNillableRemoteCacheHits sets the "remote_cache_hits" field if the given value is not nil.
func (asu *ActionSummaryUpdate) SetNillableRemoteCacheHits(i *int64) *ActionSummaryUpdate {
	if i != nil {
		asu.SetRemoteCacheHits(*i)
	}
	return asu
}

// AddRemoteCacheHits adds i to the "remote_cache_hits" field.
func (asu *ActionSummaryUpdate) AddRemoteCacheHits(i int64) *ActionSummaryUpdate {
	asu.mutation.AddRemoteCacheHits(i)
	return asu
}

// ClearRemoteCacheHits clears the value of the "remote_cache_hits" field.
func (asu *ActionSummaryUpdate) ClearRemoteCacheHits() *ActionSummaryUpdate {
	asu.mutation.ClearRemoteCacheHits()
	return asu
}

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

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

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

// AddActionDatumIDs adds the "action_data" edge to the ActionData entity by IDs.
func (asu *ActionSummaryUpdate) AddActionDatumIDs(ids ...int) *ActionSummaryUpdate {
	asu.mutation.AddActionDatumIDs(ids...)
	return asu
}

// AddActionData adds the "action_data" edges to the ActionData entity.
func (asu *ActionSummaryUpdate) AddActionData(a ...*ActionData) *ActionSummaryUpdate {
	ids := make([]int, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return asu.AddActionDatumIDs(ids...)
}

// AddRunnerCountIDs adds the "runner_count" edge to the RunnerCount entity by IDs.
func (asu *ActionSummaryUpdate) AddRunnerCountIDs(ids ...int) *ActionSummaryUpdate {
	asu.mutation.AddRunnerCountIDs(ids...)
	return asu
}

// AddRunnerCount adds the "runner_count" edges to the RunnerCount entity.
func (asu *ActionSummaryUpdate) AddRunnerCount(r ...*RunnerCount) *ActionSummaryUpdate {
	ids := make([]int, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return asu.AddRunnerCountIDs(ids...)
}

// SetActionCacheStatisticsID sets the "action_cache_statistics" edge to the ActionCacheStatistics entity by ID.
func (asu *ActionSummaryUpdate) SetActionCacheStatisticsID(id int) *ActionSummaryUpdate {
	asu.mutation.SetActionCacheStatisticsID(id)
	return asu
}

// SetNillableActionCacheStatisticsID sets the "action_cache_statistics" edge to the ActionCacheStatistics entity by ID if the given value is not nil.
func (asu *ActionSummaryUpdate) SetNillableActionCacheStatisticsID(id *int) *ActionSummaryUpdate {
	if id != nil {
		asu = asu.SetActionCacheStatisticsID(*id)
	}
	return asu
}

// SetActionCacheStatistics sets the "action_cache_statistics" edge to the ActionCacheStatistics entity.
func (asu *ActionSummaryUpdate) SetActionCacheStatistics(a *ActionCacheStatistics) *ActionSummaryUpdate {
	return asu.SetActionCacheStatisticsID(a.ID)
}

// Mutation returns the ActionSummaryMutation object of the builder.
func (asu *ActionSummaryUpdate) Mutation() *ActionSummaryMutation {
	return asu.mutation
}

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

// ClearActionData clears all "action_data" edges to the ActionData entity.
func (asu *ActionSummaryUpdate) ClearActionData() *ActionSummaryUpdate {
	asu.mutation.ClearActionData()
	return asu
}

// RemoveActionDatumIDs removes the "action_data" edge to ActionData entities by IDs.
func (asu *ActionSummaryUpdate) RemoveActionDatumIDs(ids ...int) *ActionSummaryUpdate {
	asu.mutation.RemoveActionDatumIDs(ids...)
	return asu
}

// RemoveActionData removes "action_data" edges to ActionData entities.
func (asu *ActionSummaryUpdate) RemoveActionData(a ...*ActionData) *ActionSummaryUpdate {
	ids := make([]int, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return asu.RemoveActionDatumIDs(ids...)
}

// ClearRunnerCount clears all "runner_count" edges to the RunnerCount entity.
func (asu *ActionSummaryUpdate) ClearRunnerCount() *ActionSummaryUpdate {
	asu.mutation.ClearRunnerCount()
	return asu
}

// RemoveRunnerCountIDs removes the "runner_count" edge to RunnerCount entities by IDs.
func (asu *ActionSummaryUpdate) RemoveRunnerCountIDs(ids ...int) *ActionSummaryUpdate {
	asu.mutation.RemoveRunnerCountIDs(ids...)
	return asu
}

// RemoveRunnerCount removes "runner_count" edges to RunnerCount entities.
func (asu *ActionSummaryUpdate) RemoveRunnerCount(r ...*RunnerCount) *ActionSummaryUpdate {
	ids := make([]int, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return asu.RemoveRunnerCountIDs(ids...)
}

// ClearActionCacheStatistics clears the "action_cache_statistics" edge to the ActionCacheStatistics entity.
func (asu *ActionSummaryUpdate) ClearActionCacheStatistics() *ActionSummaryUpdate {
	asu.mutation.ClearActionCacheStatistics()
	return asu
}

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

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

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

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

func (asu *ActionSummaryUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(actionsummary.Table, actionsummary.Columns, sqlgraph.NewFieldSpec(actionsummary.FieldID, field.TypeInt))
	if ps := asu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := asu.mutation.ActionsCreated(); ok {
		_spec.SetField(actionsummary.FieldActionsCreated, field.TypeInt64, value)
	}
	if value, ok := asu.mutation.AddedActionsCreated(); ok {
		_spec.AddField(actionsummary.FieldActionsCreated, field.TypeInt64, value)
	}
	if asu.mutation.ActionsCreatedCleared() {
		_spec.ClearField(actionsummary.FieldActionsCreated, field.TypeInt64)
	}
	if value, ok := asu.mutation.ActionsCreatedNotIncludingAspects(); ok {
		_spec.SetField(actionsummary.FieldActionsCreatedNotIncludingAspects, field.TypeInt64, value)
	}
	if value, ok := asu.mutation.AddedActionsCreatedNotIncludingAspects(); ok {
		_spec.AddField(actionsummary.FieldActionsCreatedNotIncludingAspects, field.TypeInt64, value)
	}
	if asu.mutation.ActionsCreatedNotIncludingAspectsCleared() {
		_spec.ClearField(actionsummary.FieldActionsCreatedNotIncludingAspects, field.TypeInt64)
	}
	if value, ok := asu.mutation.ActionsExecuted(); ok {
		_spec.SetField(actionsummary.FieldActionsExecuted, field.TypeInt64, value)
	}
	if value, ok := asu.mutation.AddedActionsExecuted(); ok {
		_spec.AddField(actionsummary.FieldActionsExecuted, field.TypeInt64, value)
	}
	if asu.mutation.ActionsExecutedCleared() {
		_spec.ClearField(actionsummary.FieldActionsExecuted, field.TypeInt64)
	}
	if value, ok := asu.mutation.RemoteCacheHits(); ok {
		_spec.SetField(actionsummary.FieldRemoteCacheHits, field.TypeInt64, value)
	}
	if value, ok := asu.mutation.AddedRemoteCacheHits(); ok {
		_spec.AddField(actionsummary.FieldRemoteCacheHits, field.TypeInt64, value)
	}
	if asu.mutation.RemoteCacheHitsCleared() {
		_spec.ClearField(actionsummary.FieldRemoteCacheHits, field.TypeInt64)
	}
	if asu.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   actionsummary.MetricsTable,
			Columns: []string{actionsummary.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asu.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   actionsummary.MetricsTable,
			Columns: []string{actionsummary.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 asu.mutation.ActionDataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.ActionDataTable,
			Columns: []string{actionsummary.ActionDataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asu.mutation.RemovedActionDataIDs(); len(nodes) > 0 && !asu.mutation.ActionDataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.ActionDataTable,
			Columns: []string{actionsummary.ActionDataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asu.mutation.ActionDataIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.ActionDataTable,
			Columns: []string{actionsummary.ActionDataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if asu.mutation.RunnerCountCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.RunnerCountTable,
			Columns: []string{actionsummary.RunnerCountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(runnercount.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asu.mutation.RemovedRunnerCountIDs(); len(nodes) > 0 && !asu.mutation.RunnerCountCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.RunnerCountTable,
			Columns: []string{actionsummary.RunnerCountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(runnercount.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asu.mutation.RunnerCountIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.RunnerCountTable,
			Columns: []string{actionsummary.RunnerCountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(runnercount.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if asu.mutation.ActionCacheStatisticsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   actionsummary.ActionCacheStatisticsTable,
			Columns: []string{actionsummary.ActionCacheStatisticsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actioncachestatistics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asu.mutation.ActionCacheStatisticsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   actionsummary.ActionCacheStatisticsTable,
			Columns: []string{actionsummary.ActionCacheStatisticsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actioncachestatistics.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, asu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{actionsummary.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	asu.mutation.done = true
	return n, nil
}

// ActionSummaryUpdateOne is the builder for updating a single ActionSummary entity.
type ActionSummaryUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ActionSummaryMutation
}

// SetActionsCreated sets the "actions_created" field.
func (asuo *ActionSummaryUpdateOne) SetActionsCreated(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.ResetActionsCreated()
	asuo.mutation.SetActionsCreated(i)
	return asuo
}

// SetNillableActionsCreated sets the "actions_created" field if the given value is not nil.
func (asuo *ActionSummaryUpdateOne) SetNillableActionsCreated(i *int64) *ActionSummaryUpdateOne {
	if i != nil {
		asuo.SetActionsCreated(*i)
	}
	return asuo
}

// AddActionsCreated adds i to the "actions_created" field.
func (asuo *ActionSummaryUpdateOne) AddActionsCreated(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.AddActionsCreated(i)
	return asuo
}

// ClearActionsCreated clears the value of the "actions_created" field.
func (asuo *ActionSummaryUpdateOne) ClearActionsCreated() *ActionSummaryUpdateOne {
	asuo.mutation.ClearActionsCreated()
	return asuo
}

// SetActionsCreatedNotIncludingAspects sets the "actions_created_not_including_aspects" field.
func (asuo *ActionSummaryUpdateOne) SetActionsCreatedNotIncludingAspects(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.ResetActionsCreatedNotIncludingAspects()
	asuo.mutation.SetActionsCreatedNotIncludingAspects(i)
	return asuo
}

// SetNillableActionsCreatedNotIncludingAspects sets the "actions_created_not_including_aspects" field if the given value is not nil.
func (asuo *ActionSummaryUpdateOne) SetNillableActionsCreatedNotIncludingAspects(i *int64) *ActionSummaryUpdateOne {
	if i != nil {
		asuo.SetActionsCreatedNotIncludingAspects(*i)
	}
	return asuo
}

// AddActionsCreatedNotIncludingAspects adds i to the "actions_created_not_including_aspects" field.
func (asuo *ActionSummaryUpdateOne) AddActionsCreatedNotIncludingAspects(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.AddActionsCreatedNotIncludingAspects(i)
	return asuo
}

// ClearActionsCreatedNotIncludingAspects clears the value of the "actions_created_not_including_aspects" field.
func (asuo *ActionSummaryUpdateOne) ClearActionsCreatedNotIncludingAspects() *ActionSummaryUpdateOne {
	asuo.mutation.ClearActionsCreatedNotIncludingAspects()
	return asuo
}

// SetActionsExecuted sets the "actions_executed" field.
func (asuo *ActionSummaryUpdateOne) SetActionsExecuted(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.ResetActionsExecuted()
	asuo.mutation.SetActionsExecuted(i)
	return asuo
}

// SetNillableActionsExecuted sets the "actions_executed" field if the given value is not nil.
func (asuo *ActionSummaryUpdateOne) SetNillableActionsExecuted(i *int64) *ActionSummaryUpdateOne {
	if i != nil {
		asuo.SetActionsExecuted(*i)
	}
	return asuo
}

// AddActionsExecuted adds i to the "actions_executed" field.
func (asuo *ActionSummaryUpdateOne) AddActionsExecuted(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.AddActionsExecuted(i)
	return asuo
}

// ClearActionsExecuted clears the value of the "actions_executed" field.
func (asuo *ActionSummaryUpdateOne) ClearActionsExecuted() *ActionSummaryUpdateOne {
	asuo.mutation.ClearActionsExecuted()
	return asuo
}

// SetRemoteCacheHits sets the "remote_cache_hits" field.
func (asuo *ActionSummaryUpdateOne) SetRemoteCacheHits(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.ResetRemoteCacheHits()
	asuo.mutation.SetRemoteCacheHits(i)
	return asuo
}

// SetNillableRemoteCacheHits sets the "remote_cache_hits" field if the given value is not nil.
func (asuo *ActionSummaryUpdateOne) SetNillableRemoteCacheHits(i *int64) *ActionSummaryUpdateOne {
	if i != nil {
		asuo.SetRemoteCacheHits(*i)
	}
	return asuo
}

// AddRemoteCacheHits adds i to the "remote_cache_hits" field.
func (asuo *ActionSummaryUpdateOne) AddRemoteCacheHits(i int64) *ActionSummaryUpdateOne {
	asuo.mutation.AddRemoteCacheHits(i)
	return asuo
}

// ClearRemoteCacheHits clears the value of the "remote_cache_hits" field.
func (asuo *ActionSummaryUpdateOne) ClearRemoteCacheHits() *ActionSummaryUpdateOne {
	asuo.mutation.ClearRemoteCacheHits()
	return asuo
}

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

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

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

// AddActionDatumIDs adds the "action_data" edge to the ActionData entity by IDs.
func (asuo *ActionSummaryUpdateOne) AddActionDatumIDs(ids ...int) *ActionSummaryUpdateOne {
	asuo.mutation.AddActionDatumIDs(ids...)
	return asuo
}

// AddActionData adds the "action_data" edges to the ActionData entity.
func (asuo *ActionSummaryUpdateOne) AddActionData(a ...*ActionData) *ActionSummaryUpdateOne {
	ids := make([]int, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return asuo.AddActionDatumIDs(ids...)
}

// AddRunnerCountIDs adds the "runner_count" edge to the RunnerCount entity by IDs.
func (asuo *ActionSummaryUpdateOne) AddRunnerCountIDs(ids ...int) *ActionSummaryUpdateOne {
	asuo.mutation.AddRunnerCountIDs(ids...)
	return asuo
}

// AddRunnerCount adds the "runner_count" edges to the RunnerCount entity.
func (asuo *ActionSummaryUpdateOne) AddRunnerCount(r ...*RunnerCount) *ActionSummaryUpdateOne {
	ids := make([]int, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return asuo.AddRunnerCountIDs(ids...)
}

// SetActionCacheStatisticsID sets the "action_cache_statistics" edge to the ActionCacheStatistics entity by ID.
func (asuo *ActionSummaryUpdateOne) SetActionCacheStatisticsID(id int) *ActionSummaryUpdateOne {
	asuo.mutation.SetActionCacheStatisticsID(id)
	return asuo
}

// SetNillableActionCacheStatisticsID sets the "action_cache_statistics" edge to the ActionCacheStatistics entity by ID if the given value is not nil.
func (asuo *ActionSummaryUpdateOne) SetNillableActionCacheStatisticsID(id *int) *ActionSummaryUpdateOne {
	if id != nil {
		asuo = asuo.SetActionCacheStatisticsID(*id)
	}
	return asuo
}

// SetActionCacheStatistics sets the "action_cache_statistics" edge to the ActionCacheStatistics entity.
func (asuo *ActionSummaryUpdateOne) SetActionCacheStatistics(a *ActionCacheStatistics) *ActionSummaryUpdateOne {
	return asuo.SetActionCacheStatisticsID(a.ID)
}

// Mutation returns the ActionSummaryMutation object of the builder.
func (asuo *ActionSummaryUpdateOne) Mutation() *ActionSummaryMutation {
	return asuo.mutation
}

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

// ClearActionData clears all "action_data" edges to the ActionData entity.
func (asuo *ActionSummaryUpdateOne) ClearActionData() *ActionSummaryUpdateOne {
	asuo.mutation.ClearActionData()
	return asuo
}

// RemoveActionDatumIDs removes the "action_data" edge to ActionData entities by IDs.
func (asuo *ActionSummaryUpdateOne) RemoveActionDatumIDs(ids ...int) *ActionSummaryUpdateOne {
	asuo.mutation.RemoveActionDatumIDs(ids...)
	return asuo
}

// RemoveActionData removes "action_data" edges to ActionData entities.
func (asuo *ActionSummaryUpdateOne) RemoveActionData(a ...*ActionData) *ActionSummaryUpdateOne {
	ids := make([]int, len(a))
	for i := range a {
		ids[i] = a[i].ID
	}
	return asuo.RemoveActionDatumIDs(ids...)
}

// ClearRunnerCount clears all "runner_count" edges to the RunnerCount entity.
func (asuo *ActionSummaryUpdateOne) ClearRunnerCount() *ActionSummaryUpdateOne {
	asuo.mutation.ClearRunnerCount()
	return asuo
}

// RemoveRunnerCountIDs removes the "runner_count" edge to RunnerCount entities by IDs.
func (asuo *ActionSummaryUpdateOne) RemoveRunnerCountIDs(ids ...int) *ActionSummaryUpdateOne {
	asuo.mutation.RemoveRunnerCountIDs(ids...)
	return asuo
}

// RemoveRunnerCount removes "runner_count" edges to RunnerCount entities.
func (asuo *ActionSummaryUpdateOne) RemoveRunnerCount(r ...*RunnerCount) *ActionSummaryUpdateOne {
	ids := make([]int, len(r))
	for i := range r {
		ids[i] = r[i].ID
	}
	return asuo.RemoveRunnerCountIDs(ids...)
}

// ClearActionCacheStatistics clears the "action_cache_statistics" edge to the ActionCacheStatistics entity.
func (asuo *ActionSummaryUpdateOne) ClearActionCacheStatistics() *ActionSummaryUpdateOne {
	asuo.mutation.ClearActionCacheStatistics()
	return asuo
}

// Where appends a list predicates to the ActionSummaryUpdate builder.
func (asuo *ActionSummaryUpdateOne) Where(ps ...predicate.ActionSummary) *ActionSummaryUpdateOne {
	asuo.mutation.Where(ps...)
	return asuo
}

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

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

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

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

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

func (asuo *ActionSummaryUpdateOne) sqlSave(ctx context.Context) (_node *ActionSummary, err error) {
	_spec := sqlgraph.NewUpdateSpec(actionsummary.Table, actionsummary.Columns, sqlgraph.NewFieldSpec(actionsummary.FieldID, field.TypeInt))
	id, ok := asuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ActionSummary.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := asuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, actionsummary.FieldID)
		for _, f := range fields {
			if !actionsummary.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != actionsummary.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := asuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := asuo.mutation.ActionsCreated(); ok {
		_spec.SetField(actionsummary.FieldActionsCreated, field.TypeInt64, value)
	}
	if value, ok := asuo.mutation.AddedActionsCreated(); ok {
		_spec.AddField(actionsummary.FieldActionsCreated, field.TypeInt64, value)
	}
	if asuo.mutation.ActionsCreatedCleared() {
		_spec.ClearField(actionsummary.FieldActionsCreated, field.TypeInt64)
	}
	if value, ok := asuo.mutation.ActionsCreatedNotIncludingAspects(); ok {
		_spec.SetField(actionsummary.FieldActionsCreatedNotIncludingAspects, field.TypeInt64, value)
	}
	if value, ok := asuo.mutation.AddedActionsCreatedNotIncludingAspects(); ok {
		_spec.AddField(actionsummary.FieldActionsCreatedNotIncludingAspects, field.TypeInt64, value)
	}
	if asuo.mutation.ActionsCreatedNotIncludingAspectsCleared() {
		_spec.ClearField(actionsummary.FieldActionsCreatedNotIncludingAspects, field.TypeInt64)
	}
	if value, ok := asuo.mutation.ActionsExecuted(); ok {
		_spec.SetField(actionsummary.FieldActionsExecuted, field.TypeInt64, value)
	}
	if value, ok := asuo.mutation.AddedActionsExecuted(); ok {
		_spec.AddField(actionsummary.FieldActionsExecuted, field.TypeInt64, value)
	}
	if asuo.mutation.ActionsExecutedCleared() {
		_spec.ClearField(actionsummary.FieldActionsExecuted, field.TypeInt64)
	}
	if value, ok := asuo.mutation.RemoteCacheHits(); ok {
		_spec.SetField(actionsummary.FieldRemoteCacheHits, field.TypeInt64, value)
	}
	if value, ok := asuo.mutation.AddedRemoteCacheHits(); ok {
		_spec.AddField(actionsummary.FieldRemoteCacheHits, field.TypeInt64, value)
	}
	if asuo.mutation.RemoteCacheHitsCleared() {
		_spec.ClearField(actionsummary.FieldRemoteCacheHits, field.TypeInt64)
	}
	if asuo.mutation.MetricsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   actionsummary.MetricsTable,
			Columns: []string{actionsummary.MetricsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(metrics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asuo.mutation.MetricsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   actionsummary.MetricsTable,
			Columns: []string{actionsummary.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 asuo.mutation.ActionDataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.ActionDataTable,
			Columns: []string{actionsummary.ActionDataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asuo.mutation.RemovedActionDataIDs(); len(nodes) > 0 && !asuo.mutation.ActionDataCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.ActionDataTable,
			Columns: []string{actionsummary.ActionDataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asuo.mutation.ActionDataIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.ActionDataTable,
			Columns: []string{actionsummary.ActionDataColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if asuo.mutation.RunnerCountCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.RunnerCountTable,
			Columns: []string{actionsummary.RunnerCountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(runnercount.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asuo.mutation.RemovedRunnerCountIDs(); len(nodes) > 0 && !asuo.mutation.RunnerCountCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.RunnerCountTable,
			Columns: []string{actionsummary.RunnerCountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(runnercount.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asuo.mutation.RunnerCountIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   actionsummary.RunnerCountTable,
			Columns: []string{actionsummary.RunnerCountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(runnercount.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if asuo.mutation.ActionCacheStatisticsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   actionsummary.ActionCacheStatisticsTable,
			Columns: []string{actionsummary.ActionCacheStatisticsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actioncachestatistics.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := asuo.mutation.ActionCacheStatisticsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: false,
			Table:   actionsummary.ActionCacheStatisticsTable,
			Columns: []string{actionsummary.ActionCacheStatisticsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actioncachestatistics.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &ActionSummary{config: asuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, asuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{actionsummary.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	asuo.mutation.done = true
	return _node, nil
}
