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

// ActionDataUpdate is the builder for updating ActionData entities.
type ActionDataUpdate struct {
	config
	hooks    []Hook
	mutation *ActionDataMutation
}

// Where appends a list predicates to the ActionDataUpdate builder.
func (adu *ActionDataUpdate) Where(ps ...predicate.ActionData) *ActionDataUpdate {
	adu.mutation.Where(ps...)
	return adu
}

// SetMnemonic sets the "mnemonic" field.
func (adu *ActionDataUpdate) SetMnemonic(s string) *ActionDataUpdate {
	adu.mutation.SetMnemonic(s)
	return adu
}

// SetNillableMnemonic sets the "mnemonic" field if the given value is not nil.
func (adu *ActionDataUpdate) SetNillableMnemonic(s *string) *ActionDataUpdate {
	if s != nil {
		adu.SetMnemonic(*s)
	}
	return adu
}

// ClearMnemonic clears the value of the "mnemonic" field.
func (adu *ActionDataUpdate) ClearMnemonic() *ActionDataUpdate {
	adu.mutation.ClearMnemonic()
	return adu
}

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

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

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

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

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

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

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

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

// SetFirstStartedMs sets the "first_started_ms" field.
func (adu *ActionDataUpdate) SetFirstStartedMs(i int64) *ActionDataUpdate {
	adu.mutation.ResetFirstStartedMs()
	adu.mutation.SetFirstStartedMs(i)
	return adu
}

// SetNillableFirstStartedMs sets the "first_started_ms" field if the given value is not nil.
func (adu *ActionDataUpdate) SetNillableFirstStartedMs(i *int64) *ActionDataUpdate {
	if i != nil {
		adu.SetFirstStartedMs(*i)
	}
	return adu
}

// AddFirstStartedMs adds i to the "first_started_ms" field.
func (adu *ActionDataUpdate) AddFirstStartedMs(i int64) *ActionDataUpdate {
	adu.mutation.AddFirstStartedMs(i)
	return adu
}

// ClearFirstStartedMs clears the value of the "first_started_ms" field.
func (adu *ActionDataUpdate) ClearFirstStartedMs() *ActionDataUpdate {
	adu.mutation.ClearFirstStartedMs()
	return adu
}

// SetLastEndedMs sets the "last_ended_ms" field.
func (adu *ActionDataUpdate) SetLastEndedMs(i int64) *ActionDataUpdate {
	adu.mutation.ResetLastEndedMs()
	adu.mutation.SetLastEndedMs(i)
	return adu
}

// SetNillableLastEndedMs sets the "last_ended_ms" field if the given value is not nil.
func (adu *ActionDataUpdate) SetNillableLastEndedMs(i *int64) *ActionDataUpdate {
	if i != nil {
		adu.SetLastEndedMs(*i)
	}
	return adu
}

// AddLastEndedMs adds i to the "last_ended_ms" field.
func (adu *ActionDataUpdate) AddLastEndedMs(i int64) *ActionDataUpdate {
	adu.mutation.AddLastEndedMs(i)
	return adu
}

// ClearLastEndedMs clears the value of the "last_ended_ms" field.
func (adu *ActionDataUpdate) ClearLastEndedMs() *ActionDataUpdate {
	adu.mutation.ClearLastEndedMs()
	return adu
}

// SetSystemTime sets the "system_time" field.
func (adu *ActionDataUpdate) SetSystemTime(i int64) *ActionDataUpdate {
	adu.mutation.ResetSystemTime()
	adu.mutation.SetSystemTime(i)
	return adu
}

// SetNillableSystemTime sets the "system_time" field if the given value is not nil.
func (adu *ActionDataUpdate) SetNillableSystemTime(i *int64) *ActionDataUpdate {
	if i != nil {
		adu.SetSystemTime(*i)
	}
	return adu
}

// AddSystemTime adds i to the "system_time" field.
func (adu *ActionDataUpdate) AddSystemTime(i int64) *ActionDataUpdate {
	adu.mutation.AddSystemTime(i)
	return adu
}

// ClearSystemTime clears the value of the "system_time" field.
func (adu *ActionDataUpdate) ClearSystemTime() *ActionDataUpdate {
	adu.mutation.ClearSystemTime()
	return adu
}

// SetUserTime sets the "user_time" field.
func (adu *ActionDataUpdate) SetUserTime(i int64) *ActionDataUpdate {
	adu.mutation.ResetUserTime()
	adu.mutation.SetUserTime(i)
	return adu
}

// SetNillableUserTime sets the "user_time" field if the given value is not nil.
func (adu *ActionDataUpdate) SetNillableUserTime(i *int64) *ActionDataUpdate {
	if i != nil {
		adu.SetUserTime(*i)
	}
	return adu
}

// AddUserTime adds i to the "user_time" field.
func (adu *ActionDataUpdate) AddUserTime(i int64) *ActionDataUpdate {
	adu.mutation.AddUserTime(i)
	return adu
}

// ClearUserTime clears the value of the "user_time" field.
func (adu *ActionDataUpdate) ClearUserTime() *ActionDataUpdate {
	adu.mutation.ClearUserTime()
	return adu
}

// SetActionSummaryID sets the "action_summary" edge to the ActionSummary entity by ID.
func (adu *ActionDataUpdate) SetActionSummaryID(id int) *ActionDataUpdate {
	adu.mutation.SetActionSummaryID(id)
	return adu
}

// SetNillableActionSummaryID sets the "action_summary" edge to the ActionSummary entity by ID if the given value is not nil.
func (adu *ActionDataUpdate) SetNillableActionSummaryID(id *int) *ActionDataUpdate {
	if id != nil {
		adu = adu.SetActionSummaryID(*id)
	}
	return adu
}

// SetActionSummary sets the "action_summary" edge to the ActionSummary entity.
func (adu *ActionDataUpdate) SetActionSummary(a *ActionSummary) *ActionDataUpdate {
	return adu.SetActionSummaryID(a.ID)
}

// Mutation returns the ActionDataMutation object of the builder.
func (adu *ActionDataUpdate) Mutation() *ActionDataMutation {
	return adu.mutation
}

// ClearActionSummary clears the "action_summary" edge to the ActionSummary entity.
func (adu *ActionDataUpdate) ClearActionSummary() *ActionDataUpdate {
	adu.mutation.ClearActionSummary()
	return adu
}

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

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

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

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

func (adu *ActionDataUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(actiondata.Table, actiondata.Columns, sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt))
	if ps := adu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := adu.mutation.Mnemonic(); ok {
		_spec.SetField(actiondata.FieldMnemonic, field.TypeString, value)
	}
	if adu.mutation.MnemonicCleared() {
		_spec.ClearField(actiondata.FieldMnemonic, field.TypeString)
	}
	if value, ok := adu.mutation.ActionsExecuted(); ok {
		_spec.SetField(actiondata.FieldActionsExecuted, field.TypeInt64, value)
	}
	if value, ok := adu.mutation.AddedActionsExecuted(); ok {
		_spec.AddField(actiondata.FieldActionsExecuted, field.TypeInt64, value)
	}
	if adu.mutation.ActionsExecutedCleared() {
		_spec.ClearField(actiondata.FieldActionsExecuted, field.TypeInt64)
	}
	if value, ok := adu.mutation.ActionsCreated(); ok {
		_spec.SetField(actiondata.FieldActionsCreated, field.TypeInt64, value)
	}
	if value, ok := adu.mutation.AddedActionsCreated(); ok {
		_spec.AddField(actiondata.FieldActionsCreated, field.TypeInt64, value)
	}
	if adu.mutation.ActionsCreatedCleared() {
		_spec.ClearField(actiondata.FieldActionsCreated, field.TypeInt64)
	}
	if value, ok := adu.mutation.FirstStartedMs(); ok {
		_spec.SetField(actiondata.FieldFirstStartedMs, field.TypeInt64, value)
	}
	if value, ok := adu.mutation.AddedFirstStartedMs(); ok {
		_spec.AddField(actiondata.FieldFirstStartedMs, field.TypeInt64, value)
	}
	if adu.mutation.FirstStartedMsCleared() {
		_spec.ClearField(actiondata.FieldFirstStartedMs, field.TypeInt64)
	}
	if value, ok := adu.mutation.LastEndedMs(); ok {
		_spec.SetField(actiondata.FieldLastEndedMs, field.TypeInt64, value)
	}
	if value, ok := adu.mutation.AddedLastEndedMs(); ok {
		_spec.AddField(actiondata.FieldLastEndedMs, field.TypeInt64, value)
	}
	if adu.mutation.LastEndedMsCleared() {
		_spec.ClearField(actiondata.FieldLastEndedMs, field.TypeInt64)
	}
	if value, ok := adu.mutation.SystemTime(); ok {
		_spec.SetField(actiondata.FieldSystemTime, field.TypeInt64, value)
	}
	if value, ok := adu.mutation.AddedSystemTime(); ok {
		_spec.AddField(actiondata.FieldSystemTime, field.TypeInt64, value)
	}
	if adu.mutation.SystemTimeCleared() {
		_spec.ClearField(actiondata.FieldSystemTime, field.TypeInt64)
	}
	if value, ok := adu.mutation.UserTime(); ok {
		_spec.SetField(actiondata.FieldUserTime, field.TypeInt64, value)
	}
	if value, ok := adu.mutation.AddedUserTime(); ok {
		_spec.AddField(actiondata.FieldUserTime, field.TypeInt64, value)
	}
	if adu.mutation.UserTimeCleared() {
		_spec.ClearField(actiondata.FieldUserTime, field.TypeInt64)
	}
	if adu.mutation.ActionSummaryCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   actiondata.ActionSummaryTable,
			Columns: []string{actiondata.ActionSummaryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actionsummary.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := adu.mutation.ActionSummaryIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   actiondata.ActionSummaryTable,
			Columns: []string{actiondata.ActionSummaryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actionsummary.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, adu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{actiondata.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	adu.mutation.done = true
	return n, nil
}

// ActionDataUpdateOne is the builder for updating a single ActionData entity.
type ActionDataUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ActionDataMutation
}

// SetMnemonic sets the "mnemonic" field.
func (aduo *ActionDataUpdateOne) SetMnemonic(s string) *ActionDataUpdateOne {
	aduo.mutation.SetMnemonic(s)
	return aduo
}

// SetNillableMnemonic sets the "mnemonic" field if the given value is not nil.
func (aduo *ActionDataUpdateOne) SetNillableMnemonic(s *string) *ActionDataUpdateOne {
	if s != nil {
		aduo.SetMnemonic(*s)
	}
	return aduo
}

// ClearMnemonic clears the value of the "mnemonic" field.
func (aduo *ActionDataUpdateOne) ClearMnemonic() *ActionDataUpdateOne {
	aduo.mutation.ClearMnemonic()
	return aduo
}

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

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

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

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

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

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

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

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

// SetFirstStartedMs sets the "first_started_ms" field.
func (aduo *ActionDataUpdateOne) SetFirstStartedMs(i int64) *ActionDataUpdateOne {
	aduo.mutation.ResetFirstStartedMs()
	aduo.mutation.SetFirstStartedMs(i)
	return aduo
}

// SetNillableFirstStartedMs sets the "first_started_ms" field if the given value is not nil.
func (aduo *ActionDataUpdateOne) SetNillableFirstStartedMs(i *int64) *ActionDataUpdateOne {
	if i != nil {
		aduo.SetFirstStartedMs(*i)
	}
	return aduo
}

// AddFirstStartedMs adds i to the "first_started_ms" field.
func (aduo *ActionDataUpdateOne) AddFirstStartedMs(i int64) *ActionDataUpdateOne {
	aduo.mutation.AddFirstStartedMs(i)
	return aduo
}

// ClearFirstStartedMs clears the value of the "first_started_ms" field.
func (aduo *ActionDataUpdateOne) ClearFirstStartedMs() *ActionDataUpdateOne {
	aduo.mutation.ClearFirstStartedMs()
	return aduo
}

// SetLastEndedMs sets the "last_ended_ms" field.
func (aduo *ActionDataUpdateOne) SetLastEndedMs(i int64) *ActionDataUpdateOne {
	aduo.mutation.ResetLastEndedMs()
	aduo.mutation.SetLastEndedMs(i)
	return aduo
}

// SetNillableLastEndedMs sets the "last_ended_ms" field if the given value is not nil.
func (aduo *ActionDataUpdateOne) SetNillableLastEndedMs(i *int64) *ActionDataUpdateOne {
	if i != nil {
		aduo.SetLastEndedMs(*i)
	}
	return aduo
}

// AddLastEndedMs adds i to the "last_ended_ms" field.
func (aduo *ActionDataUpdateOne) AddLastEndedMs(i int64) *ActionDataUpdateOne {
	aduo.mutation.AddLastEndedMs(i)
	return aduo
}

// ClearLastEndedMs clears the value of the "last_ended_ms" field.
func (aduo *ActionDataUpdateOne) ClearLastEndedMs() *ActionDataUpdateOne {
	aduo.mutation.ClearLastEndedMs()
	return aduo
}

// SetSystemTime sets the "system_time" field.
func (aduo *ActionDataUpdateOne) SetSystemTime(i int64) *ActionDataUpdateOne {
	aduo.mutation.ResetSystemTime()
	aduo.mutation.SetSystemTime(i)
	return aduo
}

// SetNillableSystemTime sets the "system_time" field if the given value is not nil.
func (aduo *ActionDataUpdateOne) SetNillableSystemTime(i *int64) *ActionDataUpdateOne {
	if i != nil {
		aduo.SetSystemTime(*i)
	}
	return aduo
}

// AddSystemTime adds i to the "system_time" field.
func (aduo *ActionDataUpdateOne) AddSystemTime(i int64) *ActionDataUpdateOne {
	aduo.mutation.AddSystemTime(i)
	return aduo
}

// ClearSystemTime clears the value of the "system_time" field.
func (aduo *ActionDataUpdateOne) ClearSystemTime() *ActionDataUpdateOne {
	aduo.mutation.ClearSystemTime()
	return aduo
}

// SetUserTime sets the "user_time" field.
func (aduo *ActionDataUpdateOne) SetUserTime(i int64) *ActionDataUpdateOne {
	aduo.mutation.ResetUserTime()
	aduo.mutation.SetUserTime(i)
	return aduo
}

// SetNillableUserTime sets the "user_time" field if the given value is not nil.
func (aduo *ActionDataUpdateOne) SetNillableUserTime(i *int64) *ActionDataUpdateOne {
	if i != nil {
		aduo.SetUserTime(*i)
	}
	return aduo
}

// AddUserTime adds i to the "user_time" field.
func (aduo *ActionDataUpdateOne) AddUserTime(i int64) *ActionDataUpdateOne {
	aduo.mutation.AddUserTime(i)
	return aduo
}

// ClearUserTime clears the value of the "user_time" field.
func (aduo *ActionDataUpdateOne) ClearUserTime() *ActionDataUpdateOne {
	aduo.mutation.ClearUserTime()
	return aduo
}

// SetActionSummaryID sets the "action_summary" edge to the ActionSummary entity by ID.
func (aduo *ActionDataUpdateOne) SetActionSummaryID(id int) *ActionDataUpdateOne {
	aduo.mutation.SetActionSummaryID(id)
	return aduo
}

// SetNillableActionSummaryID sets the "action_summary" edge to the ActionSummary entity by ID if the given value is not nil.
func (aduo *ActionDataUpdateOne) SetNillableActionSummaryID(id *int) *ActionDataUpdateOne {
	if id != nil {
		aduo = aduo.SetActionSummaryID(*id)
	}
	return aduo
}

// SetActionSummary sets the "action_summary" edge to the ActionSummary entity.
func (aduo *ActionDataUpdateOne) SetActionSummary(a *ActionSummary) *ActionDataUpdateOne {
	return aduo.SetActionSummaryID(a.ID)
}

// Mutation returns the ActionDataMutation object of the builder.
func (aduo *ActionDataUpdateOne) Mutation() *ActionDataMutation {
	return aduo.mutation
}

// ClearActionSummary clears the "action_summary" edge to the ActionSummary entity.
func (aduo *ActionDataUpdateOne) ClearActionSummary() *ActionDataUpdateOne {
	aduo.mutation.ClearActionSummary()
	return aduo
}

// Where appends a list predicates to the ActionDataUpdate builder.
func (aduo *ActionDataUpdateOne) Where(ps ...predicate.ActionData) *ActionDataUpdateOne {
	aduo.mutation.Where(ps...)
	return aduo
}

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

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

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

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

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

func (aduo *ActionDataUpdateOne) sqlSave(ctx context.Context) (_node *ActionData, err error) {
	_spec := sqlgraph.NewUpdateSpec(actiondata.Table, actiondata.Columns, sqlgraph.NewFieldSpec(actiondata.FieldID, field.TypeInt))
	id, ok := aduo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ActionData.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := aduo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, actiondata.FieldID)
		for _, f := range fields {
			if !actiondata.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != actiondata.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := aduo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := aduo.mutation.Mnemonic(); ok {
		_spec.SetField(actiondata.FieldMnemonic, field.TypeString, value)
	}
	if aduo.mutation.MnemonicCleared() {
		_spec.ClearField(actiondata.FieldMnemonic, field.TypeString)
	}
	if value, ok := aduo.mutation.ActionsExecuted(); ok {
		_spec.SetField(actiondata.FieldActionsExecuted, field.TypeInt64, value)
	}
	if value, ok := aduo.mutation.AddedActionsExecuted(); ok {
		_spec.AddField(actiondata.FieldActionsExecuted, field.TypeInt64, value)
	}
	if aduo.mutation.ActionsExecutedCleared() {
		_spec.ClearField(actiondata.FieldActionsExecuted, field.TypeInt64)
	}
	if value, ok := aduo.mutation.ActionsCreated(); ok {
		_spec.SetField(actiondata.FieldActionsCreated, field.TypeInt64, value)
	}
	if value, ok := aduo.mutation.AddedActionsCreated(); ok {
		_spec.AddField(actiondata.FieldActionsCreated, field.TypeInt64, value)
	}
	if aduo.mutation.ActionsCreatedCleared() {
		_spec.ClearField(actiondata.FieldActionsCreated, field.TypeInt64)
	}
	if value, ok := aduo.mutation.FirstStartedMs(); ok {
		_spec.SetField(actiondata.FieldFirstStartedMs, field.TypeInt64, value)
	}
	if value, ok := aduo.mutation.AddedFirstStartedMs(); ok {
		_spec.AddField(actiondata.FieldFirstStartedMs, field.TypeInt64, value)
	}
	if aduo.mutation.FirstStartedMsCleared() {
		_spec.ClearField(actiondata.FieldFirstStartedMs, field.TypeInt64)
	}
	if value, ok := aduo.mutation.LastEndedMs(); ok {
		_spec.SetField(actiondata.FieldLastEndedMs, field.TypeInt64, value)
	}
	if value, ok := aduo.mutation.AddedLastEndedMs(); ok {
		_spec.AddField(actiondata.FieldLastEndedMs, field.TypeInt64, value)
	}
	if aduo.mutation.LastEndedMsCleared() {
		_spec.ClearField(actiondata.FieldLastEndedMs, field.TypeInt64)
	}
	if value, ok := aduo.mutation.SystemTime(); ok {
		_spec.SetField(actiondata.FieldSystemTime, field.TypeInt64, value)
	}
	if value, ok := aduo.mutation.AddedSystemTime(); ok {
		_spec.AddField(actiondata.FieldSystemTime, field.TypeInt64, value)
	}
	if aduo.mutation.SystemTimeCleared() {
		_spec.ClearField(actiondata.FieldSystemTime, field.TypeInt64)
	}
	if value, ok := aduo.mutation.UserTime(); ok {
		_spec.SetField(actiondata.FieldUserTime, field.TypeInt64, value)
	}
	if value, ok := aduo.mutation.AddedUserTime(); ok {
		_spec.AddField(actiondata.FieldUserTime, field.TypeInt64, value)
	}
	if aduo.mutation.UserTimeCleared() {
		_spec.ClearField(actiondata.FieldUserTime, field.TypeInt64)
	}
	if aduo.mutation.ActionSummaryCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   actiondata.ActionSummaryTable,
			Columns: []string{actiondata.ActionSummaryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actionsummary.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := aduo.mutation.ActionSummaryIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   actiondata.ActionSummaryTable,
			Columns: []string{actiondata.ActionSummaryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(actionsummary.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &ActionData{config: aduo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, aduo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{actiondata.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	aduo.mutation.done = true
	return _node, nil
}
