// Code generated by ent, DO NOT EDIT.

package ent

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

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

// LabelTaggingCreate is the builder for creating a LabelTagging entity.
type LabelTaggingCreate struct {
	config
	mutation *LabelTaggingMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetStatus sets the "status" field.
func (ltc *LabelTaggingCreate) SetStatus(u uint8) *LabelTaggingCreate {
	ltc.mutation.SetStatus(u)
	return ltc
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (ltc *LabelTaggingCreate) SetNillableStatus(u *uint8) *LabelTaggingCreate {
	if u != nil {
		ltc.SetStatus(*u)
	}
	return ltc
}

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

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

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

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

// SetType sets the "type" field.
func (ltc *LabelTaggingCreate) SetType(i int) *LabelTaggingCreate {
	ltc.mutation.SetType(i)
	return ltc
}

// SetNillableType sets the "type" field if the given value is not nil.
func (ltc *LabelTaggingCreate) SetNillableType(i *int) *LabelTaggingCreate {
	if i != nil {
		ltc.SetType(*i)
	}
	return ltc
}

// SetConditions sets the "conditions" field.
func (ltc *LabelTaggingCreate) SetConditions(s string) *LabelTaggingCreate {
	ltc.mutation.SetConditions(s)
	return ltc
}

// SetNillableConditions sets the "conditions" field if the given value is not nil.
func (ltc *LabelTaggingCreate) SetNillableConditions(s *string) *LabelTaggingCreate {
	if s != nil {
		ltc.SetConditions(*s)
	}
	return ltc
}

// SetActionLabelAdd sets the "action_label_add" field.
func (ltc *LabelTaggingCreate) SetActionLabelAdd(u []uint64) *LabelTaggingCreate {
	ltc.mutation.SetActionLabelAdd(u)
	return ltc
}

// SetActionLabelDel sets the "action_label_del" field.
func (ltc *LabelTaggingCreate) SetActionLabelDel(u []uint64) *LabelTaggingCreate {
	ltc.mutation.SetActionLabelDel(u)
	return ltc
}

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

// Mutation returns the LabelTaggingMutation object of the builder.
func (ltc *LabelTaggingCreate) Mutation() *LabelTaggingMutation {
	return ltc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (ltc *LabelTaggingCreate) defaults() error {
	if _, ok := ltc.mutation.CreatedAt(); !ok {
		if labeltagging.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized labeltagging.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := labeltagging.DefaultCreatedAt()
		ltc.mutation.SetCreatedAt(v)
	}
	if _, ok := ltc.mutation.UpdatedAt(); !ok {
		if labeltagging.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized labeltagging.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := labeltagging.DefaultUpdatedAt()
		ltc.mutation.SetUpdatedAt(v)
	}
	if _, ok := ltc.mutation.Status(); !ok {
		v := labeltagging.DefaultStatus
		ltc.mutation.SetStatus(v)
	}
	if _, ok := ltc.mutation.OrganizationID(); !ok {
		v := labeltagging.DefaultOrganizationID
		ltc.mutation.SetOrganizationID(v)
	}
	if _, ok := ltc.mutation.GetType(); !ok {
		v := labeltagging.DefaultType
		ltc.mutation.SetType(v)
	}
	if _, ok := ltc.mutation.Conditions(); !ok {
		v := labeltagging.DefaultConditions
		ltc.mutation.SetConditions(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (ltc *LabelTaggingCreate) check() error {
	if _, ok := ltc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "LabelTagging.created_at"`)}
	}
	if _, ok := ltc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "LabelTagging.updated_at"`)}
	}
	if _, ok := ltc.mutation.OrganizationID(); !ok {
		return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "LabelTagging.organization_id"`)}
	}
	if _, ok := ltc.mutation.GetType(); !ok {
		return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "LabelTagging.type"`)}
	}
	if _, ok := ltc.mutation.Conditions(); !ok {
		return &ValidationError{Name: "conditions", err: errors.New(`ent: missing required field "LabelTagging.conditions"`)}
	}
	return nil
}

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

func (ltc *LabelTaggingCreate) createSpec() (*LabelTagging, *sqlgraph.CreateSpec) {
	var (
		_node = &LabelTagging{config: ltc.config}
		_spec = sqlgraph.NewCreateSpec(labeltagging.Table, sqlgraph.NewFieldSpec(labeltagging.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = ltc.conflict
	if id, ok := ltc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := ltc.mutation.CreatedAt(); ok {
		_spec.SetField(labeltagging.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := ltc.mutation.UpdatedAt(); ok {
		_spec.SetField(labeltagging.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := ltc.mutation.Status(); ok {
		_spec.SetField(labeltagging.FieldStatus, field.TypeUint8, value)
		_node.Status = value
	}
	if value, ok := ltc.mutation.DeletedAt(); ok {
		_spec.SetField(labeltagging.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := ltc.mutation.OrganizationID(); ok {
		_spec.SetField(labeltagging.FieldOrganizationID, field.TypeUint64, value)
		_node.OrganizationID = value
	}
	if value, ok := ltc.mutation.GetType(); ok {
		_spec.SetField(labeltagging.FieldType, field.TypeInt, value)
		_node.Type = value
	}
	if value, ok := ltc.mutation.Conditions(); ok {
		_spec.SetField(labeltagging.FieldConditions, field.TypeString, value)
		_node.Conditions = value
	}
	if value, ok := ltc.mutation.ActionLabelAdd(); ok {
		_spec.SetField(labeltagging.FieldActionLabelAdd, field.TypeJSON, value)
		_node.ActionLabelAdd = value
	}
	if value, ok := ltc.mutation.ActionLabelDel(); ok {
		_spec.SetField(labeltagging.FieldActionLabelDel, field.TypeJSON, value)
		_node.ActionLabelDel = value
	}
	return _node, _spec
}

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

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

type (
	// LabelTaggingUpsertOne is the builder for "upsert"-ing
	//  one LabelTagging node.
	LabelTaggingUpsertOne struct {
		create *LabelTaggingCreate
	}

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

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

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

// SetStatus sets the "status" field.
func (u *LabelTaggingUpsert) SetStatus(v uint8) *LabelTaggingUpsert {
	u.Set(labeltagging.FieldStatus, v)
	return u
}

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

// AddStatus adds v to the "status" field.
func (u *LabelTaggingUpsert) AddStatus(v uint8) *LabelTaggingUpsert {
	u.Add(labeltagging.FieldStatus, v)
	return u
}

// ClearStatus clears the value of the "status" field.
func (u *LabelTaggingUpsert) ClearStatus() *LabelTaggingUpsert {
	u.SetNull(labeltagging.FieldStatus)
	return u
}

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

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

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

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

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

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

// SetType sets the "type" field.
func (u *LabelTaggingUpsert) SetType(v int) *LabelTaggingUpsert {
	u.Set(labeltagging.FieldType, v)
	return u
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *LabelTaggingUpsert) UpdateType() *LabelTaggingUpsert {
	u.SetExcluded(labeltagging.FieldType)
	return u
}

// AddType adds v to the "type" field.
func (u *LabelTaggingUpsert) AddType(v int) *LabelTaggingUpsert {
	u.Add(labeltagging.FieldType, v)
	return u
}

// SetConditions sets the "conditions" field.
func (u *LabelTaggingUpsert) SetConditions(v string) *LabelTaggingUpsert {
	u.Set(labeltagging.FieldConditions, v)
	return u
}

// UpdateConditions sets the "conditions" field to the value that was provided on create.
func (u *LabelTaggingUpsert) UpdateConditions() *LabelTaggingUpsert {
	u.SetExcluded(labeltagging.FieldConditions)
	return u
}

// SetActionLabelAdd sets the "action_label_add" field.
func (u *LabelTaggingUpsert) SetActionLabelAdd(v []uint64) *LabelTaggingUpsert {
	u.Set(labeltagging.FieldActionLabelAdd, v)
	return u
}

// UpdateActionLabelAdd sets the "action_label_add" field to the value that was provided on create.
func (u *LabelTaggingUpsert) UpdateActionLabelAdd() *LabelTaggingUpsert {
	u.SetExcluded(labeltagging.FieldActionLabelAdd)
	return u
}

// ClearActionLabelAdd clears the value of the "action_label_add" field.
func (u *LabelTaggingUpsert) ClearActionLabelAdd() *LabelTaggingUpsert {
	u.SetNull(labeltagging.FieldActionLabelAdd)
	return u
}

// SetActionLabelDel sets the "action_label_del" field.
func (u *LabelTaggingUpsert) SetActionLabelDel(v []uint64) *LabelTaggingUpsert {
	u.Set(labeltagging.FieldActionLabelDel, v)
	return u
}

// UpdateActionLabelDel sets the "action_label_del" field to the value that was provided on create.
func (u *LabelTaggingUpsert) UpdateActionLabelDel() *LabelTaggingUpsert {
	u.SetExcluded(labeltagging.FieldActionLabelDel)
	return u
}

// ClearActionLabelDel clears the value of the "action_label_del" field.
func (u *LabelTaggingUpsert) ClearActionLabelDel() *LabelTaggingUpsert {
	u.SetNull(labeltagging.FieldActionLabelDel)
	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.LabelTagging.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(labeltagging.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *LabelTaggingUpsertOne) UpdateNewValues() *LabelTaggingUpsertOne {
	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(labeltagging.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(labeltagging.FieldCreatedAt)
		}
	}))
	return u
}

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

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

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

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

// SetStatus sets the "status" field.
func (u *LabelTaggingUpsertOne) SetStatus(v uint8) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *LabelTaggingUpsertOne) AddStatus(v uint8) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.AddStatus(v)
	})
}

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

// ClearStatus clears the value of the "status" field.
func (u *LabelTaggingUpsertOne) ClearStatus() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.ClearStatus()
	})
}

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

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

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

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

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

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

// SetType sets the "type" field.
func (u *LabelTaggingUpsertOne) SetType(v int) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetType(v)
	})
}

// AddType adds v to the "type" field.
func (u *LabelTaggingUpsertOne) AddType(v int) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.AddType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *LabelTaggingUpsertOne) UpdateType() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateType()
	})
}

// SetConditions sets the "conditions" field.
func (u *LabelTaggingUpsertOne) SetConditions(v string) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetConditions(v)
	})
}

// UpdateConditions sets the "conditions" field to the value that was provided on create.
func (u *LabelTaggingUpsertOne) UpdateConditions() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateConditions()
	})
}

// SetActionLabelAdd sets the "action_label_add" field.
func (u *LabelTaggingUpsertOne) SetActionLabelAdd(v []uint64) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetActionLabelAdd(v)
	})
}

// UpdateActionLabelAdd sets the "action_label_add" field to the value that was provided on create.
func (u *LabelTaggingUpsertOne) UpdateActionLabelAdd() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateActionLabelAdd()
	})
}

// ClearActionLabelAdd clears the value of the "action_label_add" field.
func (u *LabelTaggingUpsertOne) ClearActionLabelAdd() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.ClearActionLabelAdd()
	})
}

// SetActionLabelDel sets the "action_label_del" field.
func (u *LabelTaggingUpsertOne) SetActionLabelDel(v []uint64) *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetActionLabelDel(v)
	})
}

// UpdateActionLabelDel sets the "action_label_del" field to the value that was provided on create.
func (u *LabelTaggingUpsertOne) UpdateActionLabelDel() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateActionLabelDel()
	})
}

// ClearActionLabelDel clears the value of the "action_label_del" field.
func (u *LabelTaggingUpsertOne) ClearActionLabelDel() *LabelTaggingUpsertOne {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.ClearActionLabelDel()
	})
}

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

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

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

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

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

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

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

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

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

// LabelTaggingUpsertBulk is the builder for "upsert"-ing
// a bulk of LabelTagging nodes.
type LabelTaggingUpsertBulk struct {
	create *LabelTaggingCreateBulk
}

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

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

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

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

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

// SetStatus sets the "status" field.
func (u *LabelTaggingUpsertBulk) SetStatus(v uint8) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *LabelTaggingUpsertBulk) AddStatus(v uint8) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.AddStatus(v)
	})
}

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

// ClearStatus clears the value of the "status" field.
func (u *LabelTaggingUpsertBulk) ClearStatus() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.ClearStatus()
	})
}

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

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

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

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

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

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

// SetType sets the "type" field.
func (u *LabelTaggingUpsertBulk) SetType(v int) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetType(v)
	})
}

// AddType adds v to the "type" field.
func (u *LabelTaggingUpsertBulk) AddType(v int) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.AddType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *LabelTaggingUpsertBulk) UpdateType() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateType()
	})
}

// SetConditions sets the "conditions" field.
func (u *LabelTaggingUpsertBulk) SetConditions(v string) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetConditions(v)
	})
}

// UpdateConditions sets the "conditions" field to the value that was provided on create.
func (u *LabelTaggingUpsertBulk) UpdateConditions() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateConditions()
	})
}

// SetActionLabelAdd sets the "action_label_add" field.
func (u *LabelTaggingUpsertBulk) SetActionLabelAdd(v []uint64) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetActionLabelAdd(v)
	})
}

// UpdateActionLabelAdd sets the "action_label_add" field to the value that was provided on create.
func (u *LabelTaggingUpsertBulk) UpdateActionLabelAdd() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateActionLabelAdd()
	})
}

// ClearActionLabelAdd clears the value of the "action_label_add" field.
func (u *LabelTaggingUpsertBulk) ClearActionLabelAdd() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.ClearActionLabelAdd()
	})
}

// SetActionLabelDel sets the "action_label_del" field.
func (u *LabelTaggingUpsertBulk) SetActionLabelDel(v []uint64) *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.SetActionLabelDel(v)
	})
}

// UpdateActionLabelDel sets the "action_label_del" field to the value that was provided on create.
func (u *LabelTaggingUpsertBulk) UpdateActionLabelDel() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.UpdateActionLabelDel()
	})
}

// ClearActionLabelDel clears the value of the "action_label_del" field.
func (u *LabelTaggingUpsertBulk) ClearActionLabelDel() *LabelTaggingUpsertBulk {
	return u.Update(func(s *LabelTaggingUpsert) {
		s.ClearActionLabelDel()
	})
}

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

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