// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/dialect/sql/sqljson"
	"entgo.io/ent/schema/field"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
	"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)

// UsageCleanupTaskUpdate is the builder for updating UsageCleanupTask entities.
type UsageCleanupTaskUpdate struct {
	config
	hooks    []Hook
	mutation *UsageCleanupTaskMutation
}

// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
func (_u *UsageCleanupTaskUpdate) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *UsageCleanupTaskUpdate) SetUpdatedAt(v time.Time) *UsageCleanupTaskUpdate {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetStatus sets the "status" field.
func (_u *UsageCleanupTaskUpdate) SetStatus(v string) *UsageCleanupTaskUpdate {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableStatus(v *string) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetFilters sets the "filters" field.
func (_u *UsageCleanupTaskUpdate) SetFilters(v json.RawMessage) *UsageCleanupTaskUpdate {
	_u.mutation.SetFilters(v)
	return _u
}

// AppendFilters appends value to the "filters" field.
func (_u *UsageCleanupTaskUpdate) AppendFilters(v json.RawMessage) *UsageCleanupTaskUpdate {
	_u.mutation.AppendFilters(v)
	return _u
}

// SetCreatedBy sets the "created_by" field.
func (_u *UsageCleanupTaskUpdate) SetCreatedBy(v int64) *UsageCleanupTaskUpdate {
	_u.mutation.ResetCreatedBy()
	_u.mutation.SetCreatedBy(v)
	return _u
}

// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableCreatedBy(v *int64) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetCreatedBy(*v)
	}
	return _u
}

// AddCreatedBy adds value to the "created_by" field.
func (_u *UsageCleanupTaskUpdate) AddCreatedBy(v int64) *UsageCleanupTaskUpdate {
	_u.mutation.AddCreatedBy(v)
	return _u
}

// SetDeletedRows sets the "deleted_rows" field.
func (_u *UsageCleanupTaskUpdate) SetDeletedRows(v int64) *UsageCleanupTaskUpdate {
	_u.mutation.ResetDeletedRows()
	_u.mutation.SetDeletedRows(v)
	return _u
}

// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableDeletedRows(v *int64) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetDeletedRows(*v)
	}
	return _u
}

// AddDeletedRows adds value to the "deleted_rows" field.
func (_u *UsageCleanupTaskUpdate) AddDeletedRows(v int64) *UsageCleanupTaskUpdate {
	_u.mutation.AddDeletedRows(v)
	return _u
}

// SetErrorMessage sets the "error_message" field.
func (_u *UsageCleanupTaskUpdate) SetErrorMessage(v string) *UsageCleanupTaskUpdate {
	_u.mutation.SetErrorMessage(v)
	return _u
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableErrorMessage(v *string) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetErrorMessage(*v)
	}
	return _u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (_u *UsageCleanupTaskUpdate) ClearErrorMessage() *UsageCleanupTaskUpdate {
	_u.mutation.ClearErrorMessage()
	return _u
}

// SetCanceledBy sets the "canceled_by" field.
func (_u *UsageCleanupTaskUpdate) SetCanceledBy(v int64) *UsageCleanupTaskUpdate {
	_u.mutation.ResetCanceledBy()
	_u.mutation.SetCanceledBy(v)
	return _u
}

// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableCanceledBy(v *int64) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetCanceledBy(*v)
	}
	return _u
}

// AddCanceledBy adds value to the "canceled_by" field.
func (_u *UsageCleanupTaskUpdate) AddCanceledBy(v int64) *UsageCleanupTaskUpdate {
	_u.mutation.AddCanceledBy(v)
	return _u
}

// ClearCanceledBy clears the value of the "canceled_by" field.
func (_u *UsageCleanupTaskUpdate) ClearCanceledBy() *UsageCleanupTaskUpdate {
	_u.mutation.ClearCanceledBy()
	return _u
}

// SetCanceledAt sets the "canceled_at" field.
func (_u *UsageCleanupTaskUpdate) SetCanceledAt(v time.Time) *UsageCleanupTaskUpdate {
	_u.mutation.SetCanceledAt(v)
	return _u
}

// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableCanceledAt(v *time.Time) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetCanceledAt(*v)
	}
	return _u
}

// ClearCanceledAt clears the value of the "canceled_at" field.
func (_u *UsageCleanupTaskUpdate) ClearCanceledAt() *UsageCleanupTaskUpdate {
	_u.mutation.ClearCanceledAt()
	return _u
}

// SetStartedAt sets the "started_at" field.
func (_u *UsageCleanupTaskUpdate) SetStartedAt(v time.Time) *UsageCleanupTaskUpdate {
	_u.mutation.SetStartedAt(v)
	return _u
}

// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdate) SetNillableStartedAt(v *time.Time) *UsageCleanupTaskUpdate {
	if v != nil {
		_u.SetStartedAt(*v)
	}
	return _u
}

// ClearStartedAt clears the value of the "started_at" field.
func (_u *UsageCleanupTaskUpdate) ClearStartedAt() *UsageCleanupTaskUpdate {
	_u.mutation.ClearStartedAt()
	return _u
}

// SetFinishedAt sets the "finished_at" field.
func (_u *UsageCleanupTaskUpdate) SetFinishedAt(v time.Time) *UsageCleanupTaskUpdate {
	_u.mutation.SetFinishedAt(v)
	return _u
}

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

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

// Mutation returns the UsageCleanupTaskMutation object of the builder.
func (_u *UsageCleanupTaskUpdate) Mutation() *UsageCleanupTaskMutation {
	return _u.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (_u *UsageCleanupTaskUpdate) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := usagecleanuptask.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *UsageCleanupTaskUpdate) check() error {
	if v, ok := _u.mutation.Status(); ok {
		if err := usagecleanuptask.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UsageCleanupTask.status": %w`, err)}
		}
	}
	return nil
}

func (_u *UsageCleanupTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(usagecleanuptask.Table, usagecleanuptask.Columns, sqlgraph.NewFieldSpec(usagecleanuptask.FieldID, field.TypeInt64))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(usagecleanuptask.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(usagecleanuptask.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Filters(); ok {
		_spec.SetField(usagecleanuptask.FieldFilters, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedFilters(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, usagecleanuptask.FieldFilters, value)
		})
	}
	if value, ok := _u.mutation.CreatedBy(); ok {
		_spec.SetField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedCreatedBy(); ok {
		_spec.AddField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.DeletedRows(); ok {
		_spec.SetField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedDeletedRows(); ok {
		_spec.AddField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.ErrorMessage(); ok {
		_spec.SetField(usagecleanuptask.FieldErrorMessage, field.TypeString, value)
	}
	if _u.mutation.ErrorMessageCleared() {
		_spec.ClearField(usagecleanuptask.FieldErrorMessage, field.TypeString)
	}
	if value, ok := _u.mutation.CanceledBy(); ok {
		_spec.SetField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedCanceledBy(); ok {
		_spec.AddField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
	}
	if _u.mutation.CanceledByCleared() {
		_spec.ClearField(usagecleanuptask.FieldCanceledBy, field.TypeInt64)
	}
	if value, ok := _u.mutation.CanceledAt(); ok {
		_spec.SetField(usagecleanuptask.FieldCanceledAt, field.TypeTime, value)
	}
	if _u.mutation.CanceledAtCleared() {
		_spec.ClearField(usagecleanuptask.FieldCanceledAt, field.TypeTime)
	}
	if value, ok := _u.mutation.StartedAt(); ok {
		_spec.SetField(usagecleanuptask.FieldStartedAt, field.TypeTime, value)
	}
	if _u.mutation.StartedAtCleared() {
		_spec.ClearField(usagecleanuptask.FieldStartedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.FinishedAt(); ok {
		_spec.SetField(usagecleanuptask.FieldFinishedAt, field.TypeTime, value)
	}
	if _u.mutation.FinishedAtCleared() {
		_spec.ClearField(usagecleanuptask.FieldFinishedAt, field.TypeTime)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usagecleanuptask.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// UsageCleanupTaskUpdateOne is the builder for updating a single UsageCleanupTask entity.
type UsageCleanupTaskUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UsageCleanupTaskMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *UsageCleanupTaskUpdateOne) SetUpdatedAt(v time.Time) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetStatus sets the "status" field.
func (_u *UsageCleanupTaskUpdateOne) SetStatus(v string) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableStatus(v *string) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetFilters sets the "filters" field.
func (_u *UsageCleanupTaskUpdateOne) SetFilters(v json.RawMessage) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetFilters(v)
	return _u
}

// AppendFilters appends value to the "filters" field.
func (_u *UsageCleanupTaskUpdateOne) AppendFilters(v json.RawMessage) *UsageCleanupTaskUpdateOne {
	_u.mutation.AppendFilters(v)
	return _u
}

// SetCreatedBy sets the "created_by" field.
func (_u *UsageCleanupTaskUpdateOne) SetCreatedBy(v int64) *UsageCleanupTaskUpdateOne {
	_u.mutation.ResetCreatedBy()
	_u.mutation.SetCreatedBy(v)
	return _u
}

// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableCreatedBy(v *int64) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetCreatedBy(*v)
	}
	return _u
}

// AddCreatedBy adds value to the "created_by" field.
func (_u *UsageCleanupTaskUpdateOne) AddCreatedBy(v int64) *UsageCleanupTaskUpdateOne {
	_u.mutation.AddCreatedBy(v)
	return _u
}

// SetDeletedRows sets the "deleted_rows" field.
func (_u *UsageCleanupTaskUpdateOne) SetDeletedRows(v int64) *UsageCleanupTaskUpdateOne {
	_u.mutation.ResetDeletedRows()
	_u.mutation.SetDeletedRows(v)
	return _u
}

// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableDeletedRows(v *int64) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetDeletedRows(*v)
	}
	return _u
}

// AddDeletedRows adds value to the "deleted_rows" field.
func (_u *UsageCleanupTaskUpdateOne) AddDeletedRows(v int64) *UsageCleanupTaskUpdateOne {
	_u.mutation.AddDeletedRows(v)
	return _u
}

// SetErrorMessage sets the "error_message" field.
func (_u *UsageCleanupTaskUpdateOne) SetErrorMessage(v string) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetErrorMessage(v)
	return _u
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableErrorMessage(v *string) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetErrorMessage(*v)
	}
	return _u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (_u *UsageCleanupTaskUpdateOne) ClearErrorMessage() *UsageCleanupTaskUpdateOne {
	_u.mutation.ClearErrorMessage()
	return _u
}

// SetCanceledBy sets the "canceled_by" field.
func (_u *UsageCleanupTaskUpdateOne) SetCanceledBy(v int64) *UsageCleanupTaskUpdateOne {
	_u.mutation.ResetCanceledBy()
	_u.mutation.SetCanceledBy(v)
	return _u
}

// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableCanceledBy(v *int64) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetCanceledBy(*v)
	}
	return _u
}

// AddCanceledBy adds value to the "canceled_by" field.
func (_u *UsageCleanupTaskUpdateOne) AddCanceledBy(v int64) *UsageCleanupTaskUpdateOne {
	_u.mutation.AddCanceledBy(v)
	return _u
}

// ClearCanceledBy clears the value of the "canceled_by" field.
func (_u *UsageCleanupTaskUpdateOne) ClearCanceledBy() *UsageCleanupTaskUpdateOne {
	_u.mutation.ClearCanceledBy()
	return _u
}

// SetCanceledAt sets the "canceled_at" field.
func (_u *UsageCleanupTaskUpdateOne) SetCanceledAt(v time.Time) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetCanceledAt(v)
	return _u
}

// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableCanceledAt(v *time.Time) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetCanceledAt(*v)
	}
	return _u
}

// ClearCanceledAt clears the value of the "canceled_at" field.
func (_u *UsageCleanupTaskUpdateOne) ClearCanceledAt() *UsageCleanupTaskUpdateOne {
	_u.mutation.ClearCanceledAt()
	return _u
}

// SetStartedAt sets the "started_at" field.
func (_u *UsageCleanupTaskUpdateOne) SetStartedAt(v time.Time) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetStartedAt(v)
	return _u
}

// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func (_u *UsageCleanupTaskUpdateOne) SetNillableStartedAt(v *time.Time) *UsageCleanupTaskUpdateOne {
	if v != nil {
		_u.SetStartedAt(*v)
	}
	return _u
}

// ClearStartedAt clears the value of the "started_at" field.
func (_u *UsageCleanupTaskUpdateOne) ClearStartedAt() *UsageCleanupTaskUpdateOne {
	_u.mutation.ClearStartedAt()
	return _u
}

// SetFinishedAt sets the "finished_at" field.
func (_u *UsageCleanupTaskUpdateOne) SetFinishedAt(v time.Time) *UsageCleanupTaskUpdateOne {
	_u.mutation.SetFinishedAt(v)
	return _u
}

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

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

// Mutation returns the UsageCleanupTaskMutation object of the builder.
func (_u *UsageCleanupTaskUpdateOne) Mutation() *UsageCleanupTaskMutation {
	return _u.mutation
}

// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
func (_u *UsageCleanupTaskUpdateOne) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

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

// Save executes the query and returns the updated UsageCleanupTask entity.
func (_u *UsageCleanupTaskUpdateOne) Save(ctx context.Context) (*UsageCleanupTask, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (_u *UsageCleanupTaskUpdateOne) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := usagecleanuptask.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *UsageCleanupTaskUpdateOne) check() error {
	if v, ok := _u.mutation.Status(); ok {
		if err := usagecleanuptask.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UsageCleanupTask.status": %w`, err)}
		}
	}
	return nil
}

func (_u *UsageCleanupTaskUpdateOne) sqlSave(ctx context.Context) (_node *UsageCleanupTask, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(usagecleanuptask.Table, usagecleanuptask.Columns, sqlgraph.NewFieldSpec(usagecleanuptask.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageCleanupTask.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, usagecleanuptask.FieldID)
		for _, f := range fields {
			if !usagecleanuptask.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != usagecleanuptask.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(usagecleanuptask.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(usagecleanuptask.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Filters(); ok {
		_spec.SetField(usagecleanuptask.FieldFilters, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedFilters(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, usagecleanuptask.FieldFilters, value)
		})
	}
	if value, ok := _u.mutation.CreatedBy(); ok {
		_spec.SetField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedCreatedBy(); ok {
		_spec.AddField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.DeletedRows(); ok {
		_spec.SetField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedDeletedRows(); ok {
		_spec.AddField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.ErrorMessage(); ok {
		_spec.SetField(usagecleanuptask.FieldErrorMessage, field.TypeString, value)
	}
	if _u.mutation.ErrorMessageCleared() {
		_spec.ClearField(usagecleanuptask.FieldErrorMessage, field.TypeString)
	}
	if value, ok := _u.mutation.CanceledBy(); ok {
		_spec.SetField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedCanceledBy(); ok {
		_spec.AddField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
	}
	if _u.mutation.CanceledByCleared() {
		_spec.ClearField(usagecleanuptask.FieldCanceledBy, field.TypeInt64)
	}
	if value, ok := _u.mutation.CanceledAt(); ok {
		_spec.SetField(usagecleanuptask.FieldCanceledAt, field.TypeTime, value)
	}
	if _u.mutation.CanceledAtCleared() {
		_spec.ClearField(usagecleanuptask.FieldCanceledAt, field.TypeTime)
	}
	if value, ok := _u.mutation.StartedAt(); ok {
		_spec.SetField(usagecleanuptask.FieldStartedAt, field.TypeTime, value)
	}
	if _u.mutation.StartedAtCleared() {
		_spec.ClearField(usagecleanuptask.FieldStartedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.FinishedAt(); ok {
		_spec.SetField(usagecleanuptask.FieldFinishedAt, field.TypeTime, value)
	}
	if _u.mutation.FinishedAtCleared() {
		_spec.ClearField(usagecleanuptask.FieldFinishedAt, field.TypeTime)
	}
	_node = &UsageCleanupTask{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usagecleanuptask.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
