// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/employeeconfig"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// EmployeeConfigCreate is the builder for creating a EmployeeConfig entity.
type EmployeeConfigCreate struct {
	config
	mutation *EmployeeConfigMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (ecc *EmployeeConfigCreate) SetDeletedAt(t time.Time) *EmployeeConfigCreate {
	ecc.mutation.SetDeletedAt(t)
	return ecc
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (ecc *EmployeeConfigCreate) SetNillableDeletedAt(t *time.Time) *EmployeeConfigCreate {
	if t != nil {
		ecc.SetDeletedAt(*t)
	}
	return ecc
}

// SetStype sets the "stype" field.
func (ecc *EmployeeConfigCreate) SetStype(s string) *EmployeeConfigCreate {
	ecc.mutation.SetStype(s)
	return ecc
}

// SetNillableStype sets the "stype" field if the given value is not nil.
func (ecc *EmployeeConfigCreate) SetNillableStype(s *string) *EmployeeConfigCreate {
	if s != nil {
		ecc.SetStype(*s)
	}
	return ecc
}

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

// SetNillableTitle sets the "title" field if the given value is not nil.
func (ecc *EmployeeConfigCreate) SetNillableTitle(s *string) *EmployeeConfigCreate {
	if s != nil {
		ecc.SetTitle(*s)
	}
	return ecc
}

// SetPhoto sets the "photo" field.
func (ecc *EmployeeConfigCreate) SetPhoto(s string) *EmployeeConfigCreate {
	ecc.mutation.SetPhoto(s)
	return ecc
}

// SetNillablePhoto sets the "photo" field if the given value is not nil.
func (ecc *EmployeeConfigCreate) SetNillablePhoto(s *string) *EmployeeConfigCreate {
	if s != nil {
		ecc.SetPhoto(*s)
	}
	return ecc
}

// SetOrganizationID sets the "organization_id" field.
func (ecc *EmployeeConfigCreate) SetOrganizationID(u uint64) *EmployeeConfigCreate {
	ecc.mutation.SetOrganizationID(u)
	return ecc
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (ecc *EmployeeConfigCreate) SetNillableOrganizationID(u *uint64) *EmployeeConfigCreate {
	if u != nil {
		ecc.SetOrganizationID(*u)
	}
	return ecc
}

// SetID sets the "id" field.
func (ecc *EmployeeConfigCreate) SetID(u uint64) *EmployeeConfigCreate {
	ecc.mutation.SetID(u)
	return ecc
}

// Mutation returns the EmployeeConfigMutation object of the builder.
func (ecc *EmployeeConfigCreate) Mutation() *EmployeeConfigMutation {
	return ecc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (ecc *EmployeeConfigCreate) defaults() error {
	if _, ok := ecc.mutation.CreatedAt(); !ok {
		if employeeconfig.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized employeeconfig.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := employeeconfig.DefaultCreatedAt()
		ecc.mutation.SetCreatedAt(v)
	}
	if _, ok := ecc.mutation.UpdatedAt(); !ok {
		if employeeconfig.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized employeeconfig.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := employeeconfig.DefaultUpdatedAt()
		ecc.mutation.SetUpdatedAt(v)
	}
	if _, ok := ecc.mutation.Stype(); !ok {
		v := employeeconfig.DefaultStype
		ecc.mutation.SetStype(v)
	}
	if _, ok := ecc.mutation.Title(); !ok {
		v := employeeconfig.DefaultTitle
		ecc.mutation.SetTitle(v)
	}
	if _, ok := ecc.mutation.Photo(); !ok {
		v := employeeconfig.DefaultPhoto
		ecc.mutation.SetPhoto(v)
	}
	if _, ok := ecc.mutation.OrganizationID(); !ok {
		v := employeeconfig.DefaultOrganizationID
		ecc.mutation.SetOrganizationID(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (ecc *EmployeeConfigCreate) check() error {
	if _, ok := ecc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "EmployeeConfig.created_at"`)}
	}
	if _, ok := ecc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "EmployeeConfig.updated_at"`)}
	}
	if _, ok := ecc.mutation.Stype(); !ok {
		return &ValidationError{Name: "stype", err: errors.New(`ent: missing required field "EmployeeConfig.stype"`)}
	}
	if _, ok := ecc.mutation.Title(); !ok {
		return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "EmployeeConfig.title"`)}
	}
	if _, ok := ecc.mutation.Photo(); !ok {
		return &ValidationError{Name: "photo", err: errors.New(`ent: missing required field "EmployeeConfig.photo"`)}
	}
	return nil
}

func (ecc *EmployeeConfigCreate) sqlSave(ctx context.Context) (*EmployeeConfig, error) {
	if err := ecc.check(); err != nil {
		return nil, err
	}
	_node, _spec := ecc.createSpec()
	if err := sqlgraph.CreateNode(ctx, ecc.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 = uint64(id)
	}
	ecc.mutation.id = &_node.ID
	ecc.mutation.done = true
	return _node, nil
}

func (ecc *EmployeeConfigCreate) createSpec() (*EmployeeConfig, *sqlgraph.CreateSpec) {
	var (
		_node = &EmployeeConfig{config: ecc.config}
		_spec = sqlgraph.NewCreateSpec(employeeconfig.Table, sqlgraph.NewFieldSpec(employeeconfig.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = ecc.conflict
	if id, ok := ecc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := ecc.mutation.CreatedAt(); ok {
		_spec.SetField(employeeconfig.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := ecc.mutation.UpdatedAt(); ok {
		_spec.SetField(employeeconfig.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := ecc.mutation.DeletedAt(); ok {
		_spec.SetField(employeeconfig.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := ecc.mutation.Stype(); ok {
		_spec.SetField(employeeconfig.FieldStype, field.TypeString, value)
		_node.Stype = value
	}
	if value, ok := ecc.mutation.Title(); ok {
		_spec.SetField(employeeconfig.FieldTitle, field.TypeString, value)
		_node.Title = value
	}
	if value, ok := ecc.mutation.Photo(); ok {
		_spec.SetField(employeeconfig.FieldPhoto, field.TypeString, value)
		_node.Photo = value
	}
	if value, ok := ecc.mutation.OrganizationID(); ok {
		_spec.SetField(employeeconfig.FieldOrganizationID, field.TypeUint64, value)
		_node.OrganizationID = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.EmployeeConfig.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.EmployeeConfigUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (ecc *EmployeeConfigCreate) OnConflict(opts ...sql.ConflictOption) *EmployeeConfigUpsertOne {
	ecc.conflict = opts
	return &EmployeeConfigUpsertOne{
		create: ecc,
	}
}

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

type (
	// EmployeeConfigUpsertOne is the builder for "upsert"-ing
	//  one EmployeeConfig node.
	EmployeeConfigUpsertOne struct {
		create *EmployeeConfigCreate
	}

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *EmployeeConfigUpsert) SetDeletedAt(v time.Time) *EmployeeConfigUpsert {
	u.Set(employeeconfig.FieldDeletedAt, v)
	return u
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *EmployeeConfigUpsert) UpdateDeletedAt() *EmployeeConfigUpsert {
	u.SetExcluded(employeeconfig.FieldDeletedAt)
	return u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *EmployeeConfigUpsert) ClearDeletedAt() *EmployeeConfigUpsert {
	u.SetNull(employeeconfig.FieldDeletedAt)
	return u
}

// SetStype sets the "stype" field.
func (u *EmployeeConfigUpsert) SetStype(v string) *EmployeeConfigUpsert {
	u.Set(employeeconfig.FieldStype, v)
	return u
}

// UpdateStype sets the "stype" field to the value that was provided on create.
func (u *EmployeeConfigUpsert) UpdateStype() *EmployeeConfigUpsert {
	u.SetExcluded(employeeconfig.FieldStype)
	return u
}

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

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

// SetPhoto sets the "photo" field.
func (u *EmployeeConfigUpsert) SetPhoto(v string) *EmployeeConfigUpsert {
	u.Set(employeeconfig.FieldPhoto, v)
	return u
}

// UpdatePhoto sets the "photo" field to the value that was provided on create.
func (u *EmployeeConfigUpsert) UpdatePhoto() *EmployeeConfigUpsert {
	u.SetExcluded(employeeconfig.FieldPhoto)
	return u
}

// SetOrganizationID sets the "organization_id" field.
func (u *EmployeeConfigUpsert) SetOrganizationID(v uint64) *EmployeeConfigUpsert {
	u.Set(employeeconfig.FieldOrganizationID, v)
	return u
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *EmployeeConfigUpsert) UpdateOrganizationID() *EmployeeConfigUpsert {
	u.SetExcluded(employeeconfig.FieldOrganizationID)
	return u
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *EmployeeConfigUpsert) AddOrganizationID(v uint64) *EmployeeConfigUpsert {
	u.Add(employeeconfig.FieldOrganizationID, v)
	return u
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *EmployeeConfigUpsert) ClearOrganizationID() *EmployeeConfigUpsert {
	u.SetNull(employeeconfig.FieldOrganizationID)
	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.EmployeeConfig.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(employeeconfig.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *EmployeeConfigUpsertOne) UpdateNewValues() *EmployeeConfigUpsertOne {
	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(employeeconfig.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(employeeconfig.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.EmployeeConfig.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *EmployeeConfigUpsertOne) Ignore() *EmployeeConfigUpsertOne {
	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 *EmployeeConfigUpsertOne) DoNothing() *EmployeeConfigUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *EmployeeConfigUpsertOne) SetDeletedAt(v time.Time) *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *EmployeeConfigUpsertOne) UpdateDeletedAt() *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *EmployeeConfigUpsertOne) ClearDeletedAt() *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.ClearDeletedAt()
	})
}

// SetStype sets the "stype" field.
func (u *EmployeeConfigUpsertOne) SetStype(v string) *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetStype(v)
	})
}

// UpdateStype sets the "stype" field to the value that was provided on create.
func (u *EmployeeConfigUpsertOne) UpdateStype() *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdateStype()
	})
}

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

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

// SetPhoto sets the "photo" field.
func (u *EmployeeConfigUpsertOne) SetPhoto(v string) *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetPhoto(v)
	})
}

// UpdatePhoto sets the "photo" field to the value that was provided on create.
func (u *EmployeeConfigUpsertOne) UpdatePhoto() *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdatePhoto()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *EmployeeConfigUpsertOne) SetOrganizationID(v uint64) *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *EmployeeConfigUpsertOne) AddOrganizationID(v uint64) *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *EmployeeConfigUpsertOne) UpdateOrganizationID() *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *EmployeeConfigUpsertOne) ClearOrganizationID() *EmployeeConfigUpsertOne {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.ClearOrganizationID()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *EmployeeConfigUpsertOne) 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 *EmployeeConfigUpsertOne) ID(ctx context.Context) (id uint64, 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 *EmployeeConfigUpsertOne) IDX(ctx context.Context) uint64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// EmployeeConfigCreateBulk is the builder for creating many EmployeeConfig entities in bulk.
type EmployeeConfigCreateBulk struct {
	config
	err      error
	builders []*EmployeeConfigCreate
	conflict []sql.ConflictOption
}

// Save creates the EmployeeConfig entities in the database.
func (eccb *EmployeeConfigCreateBulk) Save(ctx context.Context) ([]*EmployeeConfig, error) {
	if eccb.err != nil {
		return nil, eccb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(eccb.builders))
	nodes := make([]*EmployeeConfig, len(eccb.builders))
	mutators := make([]Mutator, len(eccb.builders))
	for i := range eccb.builders {
		func(i int, root context.Context) {
			builder := eccb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*EmployeeConfigMutation)
				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, eccb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = eccb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, eccb.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 = uint64(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, eccb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.EmployeeConfig.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.EmployeeConfigUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (eccb *EmployeeConfigCreateBulk) OnConflict(opts ...sql.ConflictOption) *EmployeeConfigUpsertBulk {
	eccb.conflict = opts
	return &EmployeeConfigUpsertBulk{
		create: eccb,
	}
}

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

// EmployeeConfigUpsertBulk is the builder for "upsert"-ing
// a bulk of EmployeeConfig nodes.
type EmployeeConfigUpsertBulk struct {
	create *EmployeeConfigCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.EmployeeConfig.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(employeeconfig.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *EmployeeConfigUpsertBulk) UpdateNewValues() *EmployeeConfigUpsertBulk {
	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(employeeconfig.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(employeeconfig.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.EmployeeConfig.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *EmployeeConfigUpsertBulk) Ignore() *EmployeeConfigUpsertBulk {
	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 *EmployeeConfigUpsertBulk) DoNothing() *EmployeeConfigUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *EmployeeConfigUpsertBulk) SetDeletedAt(v time.Time) *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *EmployeeConfigUpsertBulk) UpdateDeletedAt() *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *EmployeeConfigUpsertBulk) ClearDeletedAt() *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.ClearDeletedAt()
	})
}

// SetStype sets the "stype" field.
func (u *EmployeeConfigUpsertBulk) SetStype(v string) *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetStype(v)
	})
}

// UpdateStype sets the "stype" field to the value that was provided on create.
func (u *EmployeeConfigUpsertBulk) UpdateStype() *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdateStype()
	})
}

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

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

// SetPhoto sets the "photo" field.
func (u *EmployeeConfigUpsertBulk) SetPhoto(v string) *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetPhoto(v)
	})
}

// UpdatePhoto sets the "photo" field to the value that was provided on create.
func (u *EmployeeConfigUpsertBulk) UpdatePhoto() *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdatePhoto()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *EmployeeConfigUpsertBulk) SetOrganizationID(v uint64) *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *EmployeeConfigUpsertBulk) AddOrganizationID(v uint64) *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *EmployeeConfigUpsertBulk) UpdateOrganizationID() *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *EmployeeConfigUpsertBulk) ClearOrganizationID() *EmployeeConfigUpsertBulk {
	return u.Update(func(s *EmployeeConfigUpsert) {
		s.ClearOrganizationID()
	})
}

// Exec executes the query.
func (u *EmployeeConfigUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	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 EmployeeConfigCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for EmployeeConfigCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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