func (cuo *CategoryUpdateOne) SetNillableDuration(t *time.Duration) *CategoryUpdateOne {
	if t != nil {
		cuo.SetDuration(*t)
	}
	return cuo
}
SetNillableDuration sets the "duration" field if the given value is not nil.
package ent
import (
	"context"
	"fmt"
	"time"
	"entgo.io/contrib/entgql/internal/todo/ent/category"
	"entgo.io/contrib/entgql/internal/todo/ent/predicate"
	"entgo.io/contrib/entgql/internal/todo/ent/schema/schematype"
	"entgo.io/contrib/entgql/internal/todo/ent/todo"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)
type CategoryUpdate struct {
	config
	hooks    []Hook
	mutation *CategoryMutation
}
func (cu *CategoryUpdate) Where(ps ...predicate.Category) *CategoryUpdate {
	cu.mutation.Where(ps...)
	return cu
}
func (cu *CategoryUpdate) SetText(s string) *CategoryUpdate {
	cu.mutation.SetText(s)
	return cu
}
func (cu *CategoryUpdate) SetStatus(c category.Status) *CategoryUpdate {
	cu.mutation.SetStatus(c)
	return cu
}
func (cu *CategoryUpdate) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdate {
	cu.mutation.SetConfig(sc)
	return cu
}
func (cu *CategoryUpdate) ClearConfig() *CategoryUpdate {
	cu.mutation.ClearConfig()
	return cu
}
func (cu *CategoryUpdate) SetDuration(t time.Duration) *CategoryUpdate {
	cu.mutation.ResetDuration()
	cu.mutation.SetDuration(t)
	return cu
}
func (cu *CategoryUpdate) SetNillableDuration(t *time.Duration) *CategoryUpdate {
	if t != nil {
		cu.SetDuration(*t)
	}
	return cu
}
func (cu *CategoryUpdate) AddDuration(t time.Duration) *CategoryUpdate {
	cu.mutation.AddDuration(t)
	return cu
}
func (cu *CategoryUpdate) ClearDuration() *CategoryUpdate {
	cu.mutation.ClearDuration()
	return cu
}
func (cu *CategoryUpdate) SetCount(u uint64) *CategoryUpdate {
	cu.mutation.ResetCount()
	cu.mutation.SetCount(u)
	return cu
}
func (cu *CategoryUpdate) SetNillableCount(u *uint64) *CategoryUpdate {
	if u != nil {
		cu.SetCount(*u)
	}
	return cu
}
func (cu *CategoryUpdate) AddCount(u uint64) *CategoryUpdate {
	cu.mutation.AddCount(u)
	return cu
}
func (cu *CategoryUpdate) ClearCount() *CategoryUpdate {
	cu.mutation.ClearCount()
	return cu
}
func (cu *CategoryUpdate) AddTodoIDs(ids ...int) *CategoryUpdate {
	cu.mutation.AddTodoIDs(ids...)
	return cu
}
func (cu *CategoryUpdate) AddTodos(t ...*Todo) *CategoryUpdate {
	ids := make([]int, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return cu.AddTodoIDs(ids...)
}
func (cu *CategoryUpdate) Mutation() *CategoryMutation {
	return cu.mutation
}
func (cu *CategoryUpdate) ClearTodos() *CategoryUpdate {
	cu.mutation.ClearTodos()
	return cu
}
func (cu *CategoryUpdate) RemoveTodoIDs(ids ...int) *CategoryUpdate {
	cu.mutation.RemoveTodoIDs(ids...)
	return cu
}
func (cu *CategoryUpdate) RemoveTodos(t ...*Todo) *CategoryUpdate {
	ids := make([]int, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return cu.RemoveTodoIDs(ids...)
}
func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(cu.hooks) == 0 {
		if err = cu.check(); err != nil {
			return 0, err
		}
		affected, err = cu.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*CategoryMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			if err = cu.check(); err != nil {
				return 0, err
			}
			cu.mutation = mutation
			affected, err = cu.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(cu.hooks) - 1; i >= 0; i-- {
			if cu.hooks[i] == nil {
				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = cu.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, cu.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}
func (cu *CategoryUpdate) SaveX(ctx context.Context) int {
	affected, err := cu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}
func (cu *CategoryUpdate) Exec(ctx context.Context) error {
	_, err := cu.Save(ctx)
	return err
}
func (cu *CategoryUpdate) ExecX(ctx context.Context) {
	if err := cu.Exec(ctx); err != nil {
		panic(err)
	}
}
func (cu *CategoryUpdate) check() error {
	if v, ok := cu.mutation.Text(); ok {
		if err := category.TextValidator(v); err != nil {
			return &ValidationError{Name: "text", err: fmt.Errorf("ent: validator failed for field \"text\": %w", err)}
		}
	}
	if v, ok := cu.mutation.Status(); ok {
		if err := category.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf("ent: validator failed for field \"status\": %w", err)}
		}
	}
	return nil
}
func (cu *CategoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   category.Table,
			Columns: category.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: category.FieldID,
			},
		},
	}
	if ps := cu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := cu.mutation.Text(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: category.FieldText,
		})
	}
	if value, ok := cu.mutation.Status(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeEnum,
			Value:  value,
			Column: category.FieldStatus,
		})
	}
	if value, ok := cu.mutation.Config(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeOther,
			Value:  value,
			Column: category.FieldConfig,
		})
	}
	if cu.mutation.ConfigCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeOther,
			Column: category.FieldConfig,
		})
	}
	if value, ok := cu.mutation.Duration(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeInt64,
			Value:  value,
			Column: category.FieldDuration,
		})
	}
	if value, ok := cu.mutation.AddedDuration(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeInt64,
			Value:  value,
			Column: category.FieldDuration,
		})
	}
	if cu.mutation.DurationCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeInt64,
			Column: category.FieldDuration,
		})
	}
	if value, ok := cu.mutation.Count(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeUint64,
			Value:  value,
			Column: category.FieldCount,
		})
	}
	if value, ok := cu.mutation.AddedCount(); ok {
		_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
			Type:   field.TypeUint64,
			Value:  value,
			Column: category.FieldCount,
		})
	}
	if cu.mutation.CountCleared() {
		_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
			Type:   field.TypeUint64,
			Column: category.FieldCount,
		})
	}
	if cu.mutation.TodosCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   category.TodosTable,
			Columns: []string{category.TodosColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: todo.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := cu.mutation.RemovedTodosIDs(); len(nodes) > 0 && !cu.mutation.TodosCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   category.TodosTable,
			Columns: []string{category.TodosColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: todo.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := cu.mutation.TodosIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   category.TodosTable,
			Columns: []string{category.TodosColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: todo.FieldID,
				},
			},
		}
		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, cu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{category.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{err.Error(), err}
		}
		return 0, err
	}
	return n, nil
}
type CategoryUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *CategoryMutation
}
func (cuo *CategoryUpdateOne) SetText(s string) *CategoryUpdateOne {
	cuo.mutation.SetText(s)
	return cuo
}
func (cuo *CategoryUpdateOne) SetStatus(c category.Status) *CategoryUpdateOne {
	cuo.mutation.SetStatus(c)
	return cuo
}
func (cuo *CategoryUpdateOne) SetConfig(sc *schematype.CategoryConfig) *CategoryUpdateOne {
	cuo.mutation.SetConfig(sc)
	return cuo
}
func (cuo *CategoryUpdateOne) ClearConfig() *CategoryUpdateOne {
	cuo.mutation.ClearConfig()
	return cuo
}
func (cuo *CategoryUpdateOne) SetDuration(t time.Duration) *CategoryUpdateOne {
	cuo.mutation.ResetDuration()
	cuo.mutation.SetDuration(t)
	return cuo
}