// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionarydetail"
	"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
)

// DictionaryDetailCreate is the builder for creating a DictionaryDetail entity.
type DictionaryDetailCreate struct {
	config
	mutation *DictionaryDetailMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (ddc *DictionaryDetailCreate) SetCreatedAt(t time.Time) *DictionaryDetailCreate {
	ddc.mutation.SetCreatedAt(t)
	return ddc
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (ddc *DictionaryDetailCreate) SetNillableCreatedAt(t *time.Time) *DictionaryDetailCreate {
	if t != nil {
		ddc.SetCreatedAt(*t)
	}
	return ddc
}

// SetUpdatedAt sets the "updated_at" field.
func (ddc *DictionaryDetailCreate) SetUpdatedAt(t time.Time) *DictionaryDetailCreate {
	ddc.mutation.SetUpdatedAt(t)
	return ddc
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (ddc *DictionaryDetailCreate) SetNillableUpdatedAt(t *time.Time) *DictionaryDetailCreate {
	if t != nil {
		ddc.SetUpdatedAt(*t)
	}
	return ddc
}

// SetStatus sets the "status" field.
func (ddc *DictionaryDetailCreate) SetStatus(t types.Status) *DictionaryDetailCreate {
	ddc.mutation.SetStatus(t)
	return ddc
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (ddc *DictionaryDetailCreate) SetNillableStatus(t *types.Status) *DictionaryDetailCreate {
	if t != nil {
		ddc.SetStatus(*t)
	}
	return ddc
}

// SetSort sets the "sort" field.
func (ddc *DictionaryDetailCreate) SetSort(u uint32) *DictionaryDetailCreate {
	ddc.mutation.SetSort(u)
	return ddc
}

// SetNillableSort sets the "sort" field if the given value is not nil.
func (ddc *DictionaryDetailCreate) SetNillableSort(u *uint32) *DictionaryDetailCreate {
	if u != nil {
		ddc.SetSort(*u)
	}
	return ddc
}

// SetVersion sets the "version" field.
func (ddc *DictionaryDetailCreate) SetVersion(i int64) *DictionaryDetailCreate {
	ddc.mutation.SetVersion(i)
	return ddc
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (ddc *DictionaryDetailCreate) SetNillableVersion(i *int64) *DictionaryDetailCreate {
	if i != nil {
		ddc.SetVersion(*i)
	}
	return ddc
}

// SetTitle sets the "title" field.
func (ddc *DictionaryDetailCreate) SetTitle(s string) *DictionaryDetailCreate {
	ddc.mutation.SetTitle(s)
	return ddc
}

// SetKey sets the "key" field.
func (ddc *DictionaryDetailCreate) SetKey(s string) *DictionaryDetailCreate {
	ddc.mutation.SetKey(s)
	return ddc
}

// SetValue sets the "value" field.
func (ddc *DictionaryDetailCreate) SetValue(s string) *DictionaryDetailCreate {
	ddc.mutation.SetValue(s)
	return ddc
}

// SetDictionaryID sets the "dictionary_id" field.
func (ddc *DictionaryDetailCreate) SetDictionaryID(i int64) *DictionaryDetailCreate {
	ddc.mutation.SetDictionaryID(i)
	return ddc
}

// SetID sets the "id" field.
func (ddc *DictionaryDetailCreate) SetID(i int64) *DictionaryDetailCreate {
	ddc.mutation.SetID(i)
	return ddc
}

// SetNillableID sets the "id" field if the given value is not nil.
func (ddc *DictionaryDetailCreate) SetNillableID(i *int64) *DictionaryDetailCreate {
	if i != nil {
		ddc.SetID(*i)
	}
	return ddc
}

// SetDictionary sets the "dictionary" edge to the Dictionary entity.
func (ddc *DictionaryDetailCreate) SetDictionary(d *Dictionary) *DictionaryDetailCreate {
	return ddc.SetDictionaryID(d.ID)
}

// Mutation returns the DictionaryDetailMutation object of the builder.
func (ddc *DictionaryDetailCreate) Mutation() *DictionaryDetailMutation {
	return ddc.mutation
}

// Save creates the DictionaryDetail in the database.
func (ddc *DictionaryDetailCreate) Save(ctx context.Context) (*DictionaryDetail, error) {
	if err := ddc.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, ddc.sqlSave, ddc.mutation, ddc.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (ddc *DictionaryDetailCreate) SaveX(ctx context.Context) *DictionaryDetail {
	v, err := ddc.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// defaults sets the default values of the builder before save.
func (ddc *DictionaryDetailCreate) defaults() error {
	if _, ok := ddc.mutation.CreatedAt(); !ok {
		if dictionarydetail.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized dictionarydetail.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := dictionarydetail.DefaultCreatedAt()
		ddc.mutation.SetCreatedAt(v)
	}
	if _, ok := ddc.mutation.UpdatedAt(); !ok {
		if dictionarydetail.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized dictionarydetail.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := dictionarydetail.DefaultUpdatedAt()
		ddc.mutation.SetUpdatedAt(v)
	}
	if _, ok := ddc.mutation.Status(); !ok {
		v := dictionarydetail.DefaultStatus
		ddc.mutation.SetStatus(v)
	}
	if _, ok := ddc.mutation.Sort(); !ok {
		v := dictionarydetail.DefaultSort
		ddc.mutation.SetSort(v)
	}
	if _, ok := ddc.mutation.Version(); !ok {
		v := dictionarydetail.DefaultVersion
		ddc.mutation.SetVersion(v)
	}
	if _, ok := ddc.mutation.ID(); !ok {
		if dictionarydetail.DefaultID == nil {
			return fmt.Errorf("ent: uninitialized dictionarydetail.DefaultID (forgotten import ent/runtime?)")
		}
		v := dictionarydetail.DefaultID()
		ddc.mutation.SetID(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (ddc *DictionaryDetailCreate) check() error {
	if _, ok := ddc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DictionaryDetail.created_at"`)}
	}
	if _, ok := ddc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DictionaryDetail.updated_at"`)}
	}
	if _, ok := ddc.mutation.Status(); !ok {
		return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "DictionaryDetail.status"`)}
	}
	if v, ok := ddc.mutation.Status(); ok {
		if err := dictionarydetail.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "DictionaryDetail.status": %w`, err)}
		}
	}
	if _, ok := ddc.mutation.Sort(); !ok {
		return &ValidationError{Name: "sort", err: errors.New(`ent: missing required field "DictionaryDetail.sort"`)}
	}
	if _, ok := ddc.mutation.Version(); !ok {
		return &ValidationError{Name: "version", err: errors.New(`ent: missing required field "DictionaryDetail.version"`)}
	}
	if _, ok := ddc.mutation.Title(); !ok {
		return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "DictionaryDetail.title"`)}
	}
	if _, ok := ddc.mutation.Key(); !ok {
		return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "DictionaryDetail.key"`)}
	}
	if _, ok := ddc.mutation.Value(); !ok {
		return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "DictionaryDetail.value"`)}
	}
	if _, ok := ddc.mutation.DictionaryID(); !ok {
		return &ValidationError{Name: "dictionary_id", err: errors.New(`ent: missing required field "DictionaryDetail.dictionary_id"`)}
	}
	if _, ok := ddc.mutation.DictionaryID(); !ok {
		return &ValidationError{Name: "dictionary", err: errors.New(`ent: missing required edge "DictionaryDetail.dictionary"`)}
	}
	return nil
}

func (ddc *DictionaryDetailCreate) sqlSave(ctx context.Context) (*DictionaryDetail, error) {
	if err := ddc.check(); err != nil {
		return nil, err
	}
	_node, _spec := ddc.createSpec()
	if err := sqlgraph.CreateNode(ctx, ddc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = int64(id)
	}
	ddc.mutation.id = &_node.ID
	ddc.mutation.done = true
	return _node, nil
}

func (ddc *DictionaryDetailCreate) createSpec() (*DictionaryDetail, *sqlgraph.CreateSpec) {
	var (
		_node = &DictionaryDetail{config: ddc.config}
		_spec = sqlgraph.NewCreateSpec(dictionarydetail.Table, sqlgraph.NewFieldSpec(dictionarydetail.FieldID, field.TypeInt64))
	)
	_spec.OnConflict = ddc.conflict
	if id, ok := ddc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := ddc.mutation.CreatedAt(); ok {
		_spec.SetField(dictionarydetail.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := ddc.mutation.UpdatedAt(); ok {
		_spec.SetField(dictionarydetail.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := ddc.mutation.Status(); ok {
		_spec.SetField(dictionarydetail.FieldStatus, field.TypeEnum, value)
		_node.Status = value
	}
	if value, ok := ddc.mutation.Sort(); ok {
		_spec.SetField(dictionarydetail.FieldSort, field.TypeUint32, value)
		_node.Sort = value
	}
	if value, ok := ddc.mutation.Version(); ok {
		_spec.SetField(dictionarydetail.FieldVersion, field.TypeInt64, value)
		_node.Version = value
	}
	if value, ok := ddc.mutation.Title(); ok {
		_spec.SetField(dictionarydetail.FieldTitle, field.TypeString, value)
		_node.Title = value
	}
	if value, ok := ddc.mutation.Key(); ok {
		_spec.SetField(dictionarydetail.FieldKey, field.TypeString, value)
		_node.Key = value
	}
	if value, ok := ddc.mutation.Value(); ok {
		_spec.SetField(dictionarydetail.FieldValue, field.TypeString, value)
		_node.Value = value
	}
	if nodes := ddc.mutation.DictionaryIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   dictionarydetail.DictionaryTable,
			Columns: []string{dictionarydetail.DictionaryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(dictionary.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.DictionaryID = nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.DictionaryDetail.Create().
//		SetCreatedAt(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.DictionaryDetailUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (ddc *DictionaryDetailCreate) OnConflict(opts ...sql.ConflictOption) *DictionaryDetailUpsertOne {
	ddc.conflict = opts
	return &DictionaryDetailUpsertOne{
		create: ddc,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.DictionaryDetail.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (ddc *DictionaryDetailCreate) OnConflictColumns(columns ...string) *DictionaryDetailUpsertOne {
	ddc.conflict = append(ddc.conflict, sql.ConflictColumns(columns...))
	return &DictionaryDetailUpsertOne{
		create: ddc,
	}
}

type (
	// DictionaryDetailUpsertOne is the builder for "upsert"-ing
	//  one DictionaryDetail node.
	DictionaryDetailUpsertOne struct {
		create *DictionaryDetailCreate
	}

	// DictionaryDetailUpsert is the "OnConflict" setter.
	DictionaryDetailUpsert struct {
		*sql.UpdateSet
	}
)

// SetUpdatedAt sets the "updated_at" field.
func (u *DictionaryDetailUpsert) SetUpdatedAt(v time.Time) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldUpdatedAt, v)
	return u
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateUpdatedAt() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldUpdatedAt)
	return u
}

// SetStatus sets the "status" field.
func (u *DictionaryDetailUpsert) SetStatus(v types.Status) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldStatus, v)
	return u
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateStatus() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldStatus)
	return u
}

// SetSort sets the "sort" field.
func (u *DictionaryDetailUpsert) SetSort(v uint32) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldSort, v)
	return u
}

// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateSort() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldSort)
	return u
}

// AddSort adds v to the "sort" field.
func (u *DictionaryDetailUpsert) AddSort(v uint32) *DictionaryDetailUpsert {
	u.Add(dictionarydetail.FieldSort, v)
	return u
}

// SetVersion sets the "version" field.
func (u *DictionaryDetailUpsert) SetVersion(v int64) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldVersion, v)
	return u
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateVersion() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldVersion)
	return u
}

// AddVersion adds v to the "version" field.
func (u *DictionaryDetailUpsert) AddVersion(v int64) *DictionaryDetailUpsert {
	u.Add(dictionarydetail.FieldVersion, v)
	return u
}

// SetTitle sets the "title" field.
func (u *DictionaryDetailUpsert) SetTitle(v string) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldTitle, v)
	return u
}

// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateTitle() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldTitle)
	return u
}

// SetKey sets the "key" field.
func (u *DictionaryDetailUpsert) SetKey(v string) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldKey, v)
	return u
}

// UpdateKey sets the "key" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateKey() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldKey)
	return u
}

// SetValue sets the "value" field.
func (u *DictionaryDetailUpsert) SetValue(v string) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldValue, v)
	return u
}

// UpdateValue sets the "value" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateValue() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldValue)
	return u
}

// SetDictionaryID sets the "dictionary_id" field.
func (u *DictionaryDetailUpsert) SetDictionaryID(v int64) *DictionaryDetailUpsert {
	u.Set(dictionarydetail.FieldDictionaryID, v)
	return u
}

// UpdateDictionaryID sets the "dictionary_id" field to the value that was provided on create.
func (u *DictionaryDetailUpsert) UpdateDictionaryID() *DictionaryDetailUpsert {
	u.SetExcluded(dictionarydetail.FieldDictionaryID)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.DictionaryDetail.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(dictionarydetail.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *DictionaryDetailUpsertOne) UpdateNewValues() *DictionaryDetailUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(dictionarydetail.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(dictionarydetail.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.DictionaryDetail.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *DictionaryDetailUpsertOne) Ignore() *DictionaryDetailUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *DictionaryDetailUpsertOne) DoNothing() *DictionaryDetailUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the DictionaryDetailCreate.OnConflict
// documentation for more info.
func (u *DictionaryDetailUpsertOne) Update(set func(*DictionaryDetailUpsert)) *DictionaryDetailUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&DictionaryDetailUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *DictionaryDetailUpsertOne) SetUpdatedAt(v time.Time) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateUpdatedAt() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetStatus sets the "status" field.
func (u *DictionaryDetailUpsertOne) SetStatus(v types.Status) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateStatus() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateStatus()
	})
}

// SetSort sets the "sort" field.
func (u *DictionaryDetailUpsertOne) SetSort(v uint32) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetSort(v)
	})
}

// AddSort adds v to the "sort" field.
func (u *DictionaryDetailUpsertOne) AddSort(v uint32) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.AddSort(v)
	})
}

// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateSort() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateSort()
	})
}

// SetVersion sets the "version" field.
func (u *DictionaryDetailUpsertOne) SetVersion(v int64) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetVersion(v)
	})
}

// AddVersion adds v to the "version" field.
func (u *DictionaryDetailUpsertOne) AddVersion(v int64) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.AddVersion(v)
	})
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateVersion() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateVersion()
	})
}

// SetTitle sets the "title" field.
func (u *DictionaryDetailUpsertOne) SetTitle(v string) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetTitle(v)
	})
}

// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateTitle() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateTitle()
	})
}

// SetKey sets the "key" field.
func (u *DictionaryDetailUpsertOne) SetKey(v string) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetKey(v)
	})
}

// UpdateKey sets the "key" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateKey() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateKey()
	})
}

// SetValue sets the "value" field.
func (u *DictionaryDetailUpsertOne) SetValue(v string) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetValue(v)
	})
}

// UpdateValue sets the "value" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateValue() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateValue()
	})
}

// SetDictionaryID sets the "dictionary_id" field.
func (u *DictionaryDetailUpsertOne) SetDictionaryID(v int64) *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetDictionaryID(v)
	})
}

// UpdateDictionaryID sets the "dictionary_id" field to the value that was provided on create.
func (u *DictionaryDetailUpsertOne) UpdateDictionaryID() *DictionaryDetailUpsertOne {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateDictionaryID()
	})
}

// Exec executes the query.
func (u *DictionaryDetailUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for DictionaryDetailCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

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

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *DictionaryDetailUpsertOne) ID(ctx context.Context) (id int64, err error) {
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *DictionaryDetailUpsertOne) IDX(ctx context.Context) int64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// DictionaryDetailCreateBulk is the builder for creating many DictionaryDetail entities in bulk.
type DictionaryDetailCreateBulk struct {
	config
	builders []*DictionaryDetailCreate
	conflict []sql.ConflictOption
}

// Save creates the DictionaryDetail entities in the database.
func (ddcb *DictionaryDetailCreateBulk) Save(ctx context.Context) ([]*DictionaryDetail, error) {
	specs := make([]*sqlgraph.CreateSpec, len(ddcb.builders))
	nodes := make([]*DictionaryDetail, len(ddcb.builders))
	mutators := make([]Mutator, len(ddcb.builders))
	for i := range ddcb.builders {
		func(i int, root context.Context) {
			builder := ddcb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*DictionaryDetailMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, ddcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = ddcb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, ddcb.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = int64(id)
				}
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, ddcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (ddcb *DictionaryDetailCreateBulk) SaveX(ctx context.Context) []*DictionaryDetail {
	v, err := ddcb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.DictionaryDetail.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.DictionaryDetailUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (ddcb *DictionaryDetailCreateBulk) OnConflict(opts ...sql.ConflictOption) *DictionaryDetailUpsertBulk {
	ddcb.conflict = opts
	return &DictionaryDetailUpsertBulk{
		create: ddcb,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.DictionaryDetail.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (ddcb *DictionaryDetailCreateBulk) OnConflictColumns(columns ...string) *DictionaryDetailUpsertBulk {
	ddcb.conflict = append(ddcb.conflict, sql.ConflictColumns(columns...))
	return &DictionaryDetailUpsertBulk{
		create: ddcb,
	}
}

// DictionaryDetailUpsertBulk is the builder for "upsert"-ing
// a bulk of DictionaryDetail nodes.
type DictionaryDetailUpsertBulk struct {
	create *DictionaryDetailCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.DictionaryDetail.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(dictionarydetail.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *DictionaryDetailUpsertBulk) UpdateNewValues() *DictionaryDetailUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(dictionarydetail.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(dictionarydetail.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.DictionaryDetail.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *DictionaryDetailUpsertBulk) Ignore() *DictionaryDetailUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *DictionaryDetailUpsertBulk) DoNothing() *DictionaryDetailUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the DictionaryDetailCreateBulk.OnConflict
// documentation for more info.
func (u *DictionaryDetailUpsertBulk) Update(set func(*DictionaryDetailUpsert)) *DictionaryDetailUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&DictionaryDetailUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *DictionaryDetailUpsertBulk) SetUpdatedAt(v time.Time) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateUpdatedAt() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetStatus sets the "status" field.
func (u *DictionaryDetailUpsertBulk) SetStatus(v types.Status) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateStatus() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateStatus()
	})
}

// SetSort sets the "sort" field.
func (u *DictionaryDetailUpsertBulk) SetSort(v uint32) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetSort(v)
	})
}

// AddSort adds v to the "sort" field.
func (u *DictionaryDetailUpsertBulk) AddSort(v uint32) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.AddSort(v)
	})
}

// UpdateSort sets the "sort" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateSort() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateSort()
	})
}

// SetVersion sets the "version" field.
func (u *DictionaryDetailUpsertBulk) SetVersion(v int64) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetVersion(v)
	})
}

// AddVersion adds v to the "version" field.
func (u *DictionaryDetailUpsertBulk) AddVersion(v int64) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.AddVersion(v)
	})
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateVersion() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateVersion()
	})
}

// SetTitle sets the "title" field.
func (u *DictionaryDetailUpsertBulk) SetTitle(v string) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetTitle(v)
	})
}

// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateTitle() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateTitle()
	})
}

// SetKey sets the "key" field.
func (u *DictionaryDetailUpsertBulk) SetKey(v string) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetKey(v)
	})
}

// UpdateKey sets the "key" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateKey() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateKey()
	})
}

// SetValue sets the "value" field.
func (u *DictionaryDetailUpsertBulk) SetValue(v string) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetValue(v)
	})
}

// UpdateValue sets the "value" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateValue() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateValue()
	})
}

// SetDictionaryID sets the "dictionary_id" field.
func (u *DictionaryDetailUpsertBulk) SetDictionaryID(v int64) *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.SetDictionaryID(v)
	})
}

// UpdateDictionaryID sets the "dictionary_id" field to the value that was provided on create.
func (u *DictionaryDetailUpsertBulk) UpdateDictionaryID() *DictionaryDetailUpsertBulk {
	return u.Update(func(s *DictionaryDetailUpsert) {
		s.UpdateDictionaryID()
	})
}

// Exec executes the query.
func (u *DictionaryDetailUpsertBulk) Exec(ctx context.Context) error {
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the DictionaryDetailCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for DictionaryDetailCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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