func (m TodoMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, fmt.Errorf("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}
Tx returns an `ent.Tx` for mutations that were executed in transactions;
it returns an error otherwise.
package ent
import (
	"context"
	"fmt"
	"sync"
	"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/contrib/entgql/internal/todo/ent/verysecret"
	"entgo.io/ent"
)
const (
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne
	TypeCategory   = "Category"
	TypeTodo       = "Todo"
	TypeVerySecret = "VerySecret"
)
type CategoryMutation struct {
	config
	op            Op
	typ           string
	id            *int
	text          *string
	status        *category.Status
	_config       **schematype.CategoryConfig
	duration      *time.Duration
	addduration   *time.Duration
	count         *uint64
	addcount      *uint64
	clearedFields map[string]struct{}
	todos         map[int]struct{}
	removedtodos  map[int]struct{}
	clearedtodos  bool
	done          bool
	oldValue      func(context.Context) (*Category, error)
	predicates    []predicate.Category
}
var _ ent.Mutation = (*CategoryMutation)(nil)
type categoryOption func(*CategoryMutation)
func newCategoryMutation(c config, op Op, opts ...categoryOption) *CategoryMutation {
	m := &CategoryMutation{
		config:        c,
		op:            op,
		typ:           TypeCategory,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}
func withCategoryID(id int) categoryOption {
	return func(m *CategoryMutation) {
		var (
			err   error
			once  sync.Once
			value *Category
		)
		m.oldValue = func(ctx context.Context) (*Category, error) {
			once.Do(func() {
				if m.done {
					err = fmt.Errorf("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Category.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}
func withCategory(node *Category) categoryOption {
	return func(m *CategoryMutation) {
		m.oldValue = func(context.Context) (*Category, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}
func (m CategoryMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}
func (m CategoryMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, fmt.Errorf("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}
func (m *CategoryMutation) ID() (id int, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}
func (m *CategoryMutation) SetText(s string) {
	m.text = &s
}
func (m *CategoryMutation) Text() (r string, exists bool) {
	v := m.text
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) OldText(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldText is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldText requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldText: %w", err)
	}
	return oldValue.Text, nil
}
func (m *CategoryMutation) ResetText() {
	m.text = nil
}
func (m *CategoryMutation) SetStatus(c category.Status) {
	m.status = &c
}
func (m *CategoryMutation) Status() (r category.Status, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) OldStatus(ctx context.Context) (v category.Status, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldStatus requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStatus: %w", err)
	}
	return oldValue.Status, nil
}
func (m *CategoryMutation) ResetStatus() {
	m.status = nil
}
func (m *CategoryMutation) SetConfig(sc *schematype.CategoryConfig) {
	m._config = &sc
}
func (m *CategoryMutation) Config() (r *schematype.CategoryConfig, exists bool) {
	v := m._config
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) OldConfig(ctx context.Context) (v *schematype.CategoryConfig, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldConfig is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldConfig requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldConfig: %w", err)
	}
	return oldValue.Config, nil
}
func (m *CategoryMutation) ClearConfig() {
	m._config = nil
	m.clearedFields[category.FieldConfig] = struct{}{}
}
func (m *CategoryMutation) ConfigCleared() bool {
	_, ok := m.clearedFields[category.FieldConfig]
	return ok
}
func (m *CategoryMutation) ResetConfig() {
	m._config = nil
	delete(m.clearedFields, category.FieldConfig)
}
func (m *CategoryMutation) SetDuration(t time.Duration) {
	m.duration = &t
	m.addduration = nil
}
func (m *CategoryMutation) Duration() (r time.Duration, exists bool) {
	v := m.duration
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) OldDuration(ctx context.Context) (v time.Duration, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldDuration is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldDuration requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDuration: %w", err)
	}
	return oldValue.Duration, nil
}
func (m *CategoryMutation) AddDuration(t time.Duration) {
	if m.addduration != nil {
		*m.addduration += t
	} else {
		m.addduration = &t
	}
}
func (m *CategoryMutation) AddedDuration() (r time.Duration, exists bool) {
	v := m.addduration
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) ClearDuration() {
	m.duration = nil
	m.addduration = nil
	m.clearedFields[category.FieldDuration] = struct{}{}
}
func (m *CategoryMutation) DurationCleared() bool {
	_, ok := m.clearedFields[category.FieldDuration]
	return ok
}
func (m *CategoryMutation) ResetDuration() {
	m.duration = nil
	m.addduration = nil
	delete(m.clearedFields, category.FieldDuration)
}
func (m *CategoryMutation) SetCount(u uint64) {
	m.count = &u
	m.addcount = nil
}
func (m *CategoryMutation) Count() (r uint64, exists bool) {
	v := m.count
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) OldCount(ctx context.Context) (v uint64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldCount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldCount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCount: %w", err)
	}
	return oldValue.Count, nil
}
func (m *CategoryMutation) AddCount(u uint64) {
	if m.addcount != nil {
		*m.addcount += u
	} else {
		m.addcount = &u
	}
}
func (m *CategoryMutation) AddedCount() (r uint64, exists bool) {
	v := m.addcount
	if v == nil {
		return
	}
	return *v, true
}
func (m *CategoryMutation) ClearCount() {
	m.count = nil
	m.addcount = nil
	m.clearedFields[category.FieldCount] = struct{}{}
}
func (m *CategoryMutation) CountCleared() bool {
	_, ok := m.clearedFields[category.FieldCount]
	return ok
}
func (m *CategoryMutation) ResetCount() {
	m.count = nil
	m.addcount = nil
	delete(m.clearedFields, category.FieldCount)
}
func (m *CategoryMutation) AddTodoIDs(ids ...int) {
	if m.todos == nil {
		m.todos = make(map[int]struct{})
	}
	for i := range ids {
		m.todos[ids[i]] = struct{}{}
	}
}
func (m *CategoryMutation) ClearTodos() {
	m.clearedtodos = true
}
func (m *CategoryMutation) TodosCleared() bool {
	return m.clearedtodos
}
func (m *CategoryMutation) RemoveTodoIDs(ids ...int) {
	if m.removedtodos == nil {
		m.removedtodos = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.todos, ids[i])
		m.removedtodos[ids[i]] = struct{}{}
	}
}
func (m *CategoryMutation) RemovedTodosIDs() (ids []int) {
	for id := range m.removedtodos {
		ids = append(ids, id)
	}
	return
}
func (m *CategoryMutation) TodosIDs() (ids []int) {
	for id := range m.todos {
		ids = append(ids, id)
	}
	return
}
func (m *CategoryMutation) ResetTodos() {
	m.todos = nil
	m.clearedtodos = false
	m.removedtodos = nil
}
func (m *CategoryMutation) Where(ps ...predicate.Category) {
	m.predicates = append(m.predicates, ps...)
}
func (m *CategoryMutation) Op() Op {
	return m.op
}
func (m *CategoryMutation) Type() string {
	return m.typ
}
func (m *CategoryMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.text != nil {
		fields = append(fields, category.FieldText)
	}
	if m.status != nil {
		fields = append(fields, category.FieldStatus)
	}
	if m._config != nil {
		fields = append(fields, category.FieldConfig)
	}
	if m.duration != nil {
		fields = append(fields, category.FieldDuration)
	}
	if m.count != nil {
		fields = append(fields, category.FieldCount)
	}
	return fields
}
func (m *CategoryMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case category.FieldText:
		return m.Text()
	case category.FieldStatus:
		return m.Status()
	case category.FieldConfig:
		return m.Config()
	case category.FieldDuration:
		return m.Duration()
	case category.FieldCount:
		return m.Count()
	}
	return nil, false
}
func (m *CategoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case category.FieldText:
		return m.OldText(ctx)
	case category.FieldStatus:
		return m.OldStatus(ctx)
	case category.FieldConfig:
		return m.OldConfig(ctx)
	case category.FieldDuration:
		return m.OldDuration(ctx)
	case category.FieldCount:
		return m.OldCount(ctx)
	}
	return nil, fmt.Errorf("unknown Category field %s", name)
}
func (m *CategoryMutation) SetField(name string, value ent.Value) error {
	switch name {
	case category.FieldText:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetText(v)
		return nil
	case category.FieldStatus:
		v, ok := value.(category.Status)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case category.FieldConfig:
		v, ok := value.(*schematype.CategoryConfig)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConfig(v)
		return nil
	case category.FieldDuration:
		v, ok := value.(time.Duration)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDuration(v)
		return nil
	case category.FieldCount:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCount(v)
		return nil
	}
	return fmt.Errorf("unknown Category field %s", name)
}
func (m *CategoryMutation) AddedFields() []string {
	var fields []string
	if m.addduration != nil {
		fields = append(fields, category.FieldDuration)
	}
	if m.addcount != nil {
		fields = append(fields, category.FieldCount)
	}
	return fields
}
func (m *CategoryMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case category.FieldDuration:
		return m.AddedDuration()
	case category.FieldCount:
		return m.AddedCount()
	}
	return nil, false
}
func (m *CategoryMutation) AddField(name string, value ent.Value) error {
	switch name {
	case category.FieldDuration:
		v, ok := value.(time.Duration)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDuration(v)
		return nil
	case category.FieldCount:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCount(v)
		return nil
	}
	return fmt.Errorf("unknown Category numeric field %s", name)
}
func (m *CategoryMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(category.FieldConfig) {
		fields = append(fields, category.FieldConfig)
	}
	if m.FieldCleared(category.FieldDuration) {
		fields = append(fields, category.FieldDuration)
	}
	if m.FieldCleared(category.FieldCount) {
		fields = append(fields, category.FieldCount)
	}
	return fields
}
func (m *CategoryMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}
func (m *CategoryMutation) ClearField(name string) error {
	switch name {
	case category.FieldConfig:
		m.ClearConfig()
		return nil
	case category.FieldDuration:
		m.ClearDuration()
		return nil
	case category.FieldCount:
		m.ClearCount()
		return nil
	}
	return fmt.Errorf("unknown Category nullable field %s", name)
}
func (m *CategoryMutation) ResetField(name string) error {
	switch name {
	case category.FieldText:
		m.ResetText()
		return nil
	case category.FieldStatus:
		m.ResetStatus()
		return nil
	case category.FieldConfig:
		m.ResetConfig()
		return nil
	case category.FieldDuration:
		m.ResetDuration()
		return nil
	case category.FieldCount:
		m.ResetCount()
		return nil
	}
	return fmt.Errorf("unknown Category field %s", name)
}
func (m *CategoryMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.todos != nil {
		edges = append(edges, category.EdgeTodos)
	}
	return edges
}
func (m *CategoryMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case category.EdgeTodos:
		ids := make([]ent.Value, 0, len(m.todos))
		for id := range m.todos {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}
func (m *CategoryMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedtodos != nil {
		edges = append(edges, category.EdgeTodos)
	}
	return edges
}
func (m *CategoryMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case category.EdgeTodos:
		ids := make([]ent.Value, 0, len(m.removedtodos))
		for id := range m.removedtodos {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}
func (m *CategoryMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedtodos {
		edges = append(edges, category.EdgeTodos)
	}
	return edges
}
func (m *CategoryMutation) EdgeCleared(name string) bool {
	switch name {
	case category.EdgeTodos:
		return m.clearedtodos
	}
	return false
}
func (m *CategoryMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Category unique edge %s", name)
}
func (m *CategoryMutation) ResetEdge(name string) error {
	switch name {
	case category.EdgeTodos:
		m.ResetTodos()
		return nil
	}
	return fmt.Errorf("unknown Category edge %s", name)
}
type TodoMutation struct {
	config
	op              Op
	typ             string
	id              *int
	created_at      *time.Time
	status          *todo.Status
	priority        *int
	addpriority     *int
	text            *string
	blob            *[]byte
	clearedFields   map[string]struct{}
	parent          *int
	clearedparent   bool
	children        map[int]struct{}
	removedchildren map[int]struct{}
	clearedchildren bool
	category        *int
	clearedcategory bool
	secret          *int
	clearedsecret   bool
	done            bool
	oldValue        func(context.Context) (*Todo, error)
	predicates      []predicate.Todo
}
var _ ent.Mutation = (*TodoMutation)(nil)
type todoOption func(*TodoMutation)
func newTodoMutation(c config, op Op, opts ...todoOption) *TodoMutation {
	m := &TodoMutation{
		config:        c,
		op:            op,
		typ:           TypeTodo,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}
func withTodoID(id int) todoOption {
	return func(m *TodoMutation) {
		var (
			err   error
			once  sync.Once
			value *Todo
		)
		m.oldValue = func(ctx context.Context) (*Todo, error) {
			once.Do(func() {
				if m.done {
					err = fmt.Errorf("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Todo.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}
func withTodo(node *Todo) todoOption {
	return func(m *TodoMutation) {
		m.oldValue = func(context.Context) (*Todo, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}
func (m TodoMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}