// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
	"github.com/lightsparkdev/spark/common/keys"
	"github.com/lightsparkdev/spark/so/ent/l1tokencreate"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
)

// L1TokenCreateCreate is the builder for creating a L1TokenCreate entity.
type L1TokenCreateCreate struct {
	config
	mutation *L1TokenCreateMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreateTime sets the "create_time" field.
func (lcc *L1TokenCreateCreate) SetCreateTime(t time.Time) *L1TokenCreateCreate {
	lcc.mutation.SetCreateTime(t)
	return lcc
}

// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (lcc *L1TokenCreateCreate) SetNillableCreateTime(t *time.Time) *L1TokenCreateCreate {
	if t != nil {
		lcc.SetCreateTime(*t)
	}
	return lcc
}

// SetUpdateTime sets the "update_time" field.
func (lcc *L1TokenCreateCreate) SetUpdateTime(t time.Time) *L1TokenCreateCreate {
	lcc.mutation.SetUpdateTime(t)
	return lcc
}

// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
func (lcc *L1TokenCreateCreate) SetNillableUpdateTime(t *time.Time) *L1TokenCreateCreate {
	if t != nil {
		lcc.SetUpdateTime(*t)
	}
	return lcc
}

// SetIssuerPublicKey sets the "issuer_public_key" field.
func (lcc *L1TokenCreateCreate) SetIssuerPublicKey(k keys.Public) *L1TokenCreateCreate {
	lcc.mutation.SetIssuerPublicKey(k)
	return lcc
}

// SetTokenName sets the "token_name" field.
func (lcc *L1TokenCreateCreate) SetTokenName(s string) *L1TokenCreateCreate {
	lcc.mutation.SetTokenName(s)
	return lcc
}

// SetTokenTicker sets the "token_ticker" field.
func (lcc *L1TokenCreateCreate) SetTokenTicker(s string) *L1TokenCreateCreate {
	lcc.mutation.SetTokenTicker(s)
	return lcc
}

// SetDecimals sets the "decimals" field.
func (lcc *L1TokenCreateCreate) SetDecimals(u uint8) *L1TokenCreateCreate {
	lcc.mutation.SetDecimals(u)
	return lcc
}

// SetMaxSupply sets the "max_supply" field.
func (lcc *L1TokenCreateCreate) SetMaxSupply(b []byte) *L1TokenCreateCreate {
	lcc.mutation.SetMaxSupply(b)
	return lcc
}

// SetIsFreezable sets the "is_freezable" field.
func (lcc *L1TokenCreateCreate) SetIsFreezable(b bool) *L1TokenCreateCreate {
	lcc.mutation.SetIsFreezable(b)
	return lcc
}

// SetNetwork sets the "network" field.
func (lcc *L1TokenCreateCreate) SetNetwork(s schematype.Network) *L1TokenCreateCreate {
	lcc.mutation.SetNetwork(s)
	return lcc
}

// SetTokenIdentifier sets the "token_identifier" field.
func (lcc *L1TokenCreateCreate) SetTokenIdentifier(b []byte) *L1TokenCreateCreate {
	lcc.mutation.SetTokenIdentifier(b)
	return lcc
}

// SetTransactionID sets the "transaction_id" field.
func (lcc *L1TokenCreateCreate) SetTransactionID(b []byte) *L1TokenCreateCreate {
	lcc.mutation.SetTransactionID(b)
	return lcc
}

// SetID sets the "id" field.
func (lcc *L1TokenCreateCreate) SetID(u uuid.UUID) *L1TokenCreateCreate {
	lcc.mutation.SetID(u)
	return lcc
}

// SetNillableID sets the "id" field if the given value is not nil.
func (lcc *L1TokenCreateCreate) SetNillableID(u *uuid.UUID) *L1TokenCreateCreate {
	if u != nil {
		lcc.SetID(*u)
	}
	return lcc
}

// Mutation returns the L1TokenCreateMutation object of the builder.
func (lcc *L1TokenCreateCreate) Mutation() *L1TokenCreateMutation {
	return lcc.mutation
}

// Save creates the L1TokenCreate in the database.
func (lcc *L1TokenCreateCreate) Save(ctx context.Context) (*L1TokenCreate, error) {
	lcc.defaults()
	return withHooks(ctx, lcc.sqlSave, lcc.mutation, lcc.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (lcc *L1TokenCreateCreate) defaults() {
	if _, ok := lcc.mutation.CreateTime(); !ok {
		v := l1tokencreate.DefaultCreateTime()
		lcc.mutation.SetCreateTime(v)
	}
	if _, ok := lcc.mutation.UpdateTime(); !ok {
		v := l1tokencreate.DefaultUpdateTime()
		lcc.mutation.SetUpdateTime(v)
	}
	if _, ok := lcc.mutation.ID(); !ok {
		v := l1tokencreate.DefaultID()
		lcc.mutation.SetID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (lcc *L1TokenCreateCreate) check() error {
	if _, ok := lcc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "L1TokenCreate.create_time"`)}
	}
	if _, ok := lcc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "L1TokenCreate.update_time"`)}
	}
	if _, ok := lcc.mutation.IssuerPublicKey(); !ok {
		return &ValidationError{Name: "issuer_public_key", err: errors.New(`ent: missing required field "L1TokenCreate.issuer_public_key"`)}
	}
	if _, ok := lcc.mutation.TokenName(); !ok {
		return &ValidationError{Name: "token_name", err: errors.New(`ent: missing required field "L1TokenCreate.token_name"`)}
	}
	if v, ok := lcc.mutation.TokenName(); ok {
		if err := l1tokencreate.TokenNameValidator(v); err != nil {
			return &ValidationError{Name: "token_name", err: fmt.Errorf(`ent: validator failed for field "L1TokenCreate.token_name": %w`, err)}
		}
	}
	if _, ok := lcc.mutation.TokenTicker(); !ok {
		return &ValidationError{Name: "token_ticker", err: errors.New(`ent: missing required field "L1TokenCreate.token_ticker"`)}
	}
	if v, ok := lcc.mutation.TokenTicker(); ok {
		if err := l1tokencreate.TokenTickerValidator(v); err != nil {
			return &ValidationError{Name: "token_ticker", err: fmt.Errorf(`ent: validator failed for field "L1TokenCreate.token_ticker": %w`, err)}
		}
	}
	if _, ok := lcc.mutation.Decimals(); !ok {
		return &ValidationError{Name: "decimals", err: errors.New(`ent: missing required field "L1TokenCreate.decimals"`)}
	}
	if _, ok := lcc.mutation.MaxSupply(); !ok {
		return &ValidationError{Name: "max_supply", err: errors.New(`ent: missing required field "L1TokenCreate.max_supply"`)}
	}
	if v, ok := lcc.mutation.MaxSupply(); ok {
		if err := l1tokencreate.MaxSupplyValidator(v); err != nil {
			return &ValidationError{Name: "max_supply", err: fmt.Errorf(`ent: validator failed for field "L1TokenCreate.max_supply": %w`, err)}
		}
	}
	if _, ok := lcc.mutation.IsFreezable(); !ok {
		return &ValidationError{Name: "is_freezable", err: errors.New(`ent: missing required field "L1TokenCreate.is_freezable"`)}
	}
	if _, ok := lcc.mutation.Network(); !ok {
		return &ValidationError{Name: "network", err: errors.New(`ent: missing required field "L1TokenCreate.network"`)}
	}
	if v, ok := lcc.mutation.Network(); ok {
		if err := l1tokencreate.NetworkValidator(v); err != nil {
			return &ValidationError{Name: "network", err: fmt.Errorf(`ent: validator failed for field "L1TokenCreate.network": %w`, err)}
		}
	}
	if _, ok := lcc.mutation.TokenIdentifier(); !ok {
		return &ValidationError{Name: "token_identifier", err: errors.New(`ent: missing required field "L1TokenCreate.token_identifier"`)}
	}
	if v, ok := lcc.mutation.TokenIdentifier(); ok {
		if err := l1tokencreate.TokenIdentifierValidator(v); err != nil {
			return &ValidationError{Name: "token_identifier", err: fmt.Errorf(`ent: validator failed for field "L1TokenCreate.token_identifier": %w`, err)}
		}
	}
	if _, ok := lcc.mutation.TransactionID(); !ok {
		return &ValidationError{Name: "transaction_id", err: errors.New(`ent: missing required field "L1TokenCreate.transaction_id"`)}
	}
	if v, ok := lcc.mutation.TransactionID(); ok {
		if err := l1tokencreate.TransactionIDValidator(v); err != nil {
			return &ValidationError{Name: "transaction_id", err: fmt.Errorf(`ent: validator failed for field "L1TokenCreate.transaction_id": %w`, err)}
		}
	}
	return nil
}

func (lcc *L1TokenCreateCreate) sqlSave(ctx context.Context) (*L1TokenCreate, error) {
	if err := lcc.check(); err != nil {
		return nil, err
	}
	_node, _spec := lcc.createSpec()
	if err := sqlgraph.CreateNode(ctx, lcc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != nil {
		if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
			_node.ID = *id
		} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
			return nil, err
		}
	}
	lcc.mutation.id = &_node.ID
	lcc.mutation.done = true
	return _node, nil
}

func (lcc *L1TokenCreateCreate) createSpec() (*L1TokenCreate, *sqlgraph.CreateSpec) {
	var (
		_node = &L1TokenCreate{config: lcc.config}
		_spec = sqlgraph.NewCreateSpec(l1tokencreate.Table, sqlgraph.NewFieldSpec(l1tokencreate.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = lcc.conflict
	if id, ok := lcc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := lcc.mutation.CreateTime(); ok {
		_spec.SetField(l1tokencreate.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := lcc.mutation.UpdateTime(); ok {
		_spec.SetField(l1tokencreate.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := lcc.mutation.IssuerPublicKey(); ok {
		_spec.SetField(l1tokencreate.FieldIssuerPublicKey, field.TypeBytes, value)
		_node.IssuerPublicKey = value
	}
	if value, ok := lcc.mutation.TokenName(); ok {
		_spec.SetField(l1tokencreate.FieldTokenName, field.TypeString, value)
		_node.TokenName = value
	}
	if value, ok := lcc.mutation.TokenTicker(); ok {
		_spec.SetField(l1tokencreate.FieldTokenTicker, field.TypeString, value)
		_node.TokenTicker = value
	}
	if value, ok := lcc.mutation.Decimals(); ok {
		_spec.SetField(l1tokencreate.FieldDecimals, field.TypeUint8, value)
		_node.Decimals = value
	}
	if value, ok := lcc.mutation.MaxSupply(); ok {
		_spec.SetField(l1tokencreate.FieldMaxSupply, field.TypeBytes, value)
		_node.MaxSupply = value
	}
	if value, ok := lcc.mutation.IsFreezable(); ok {
		_spec.SetField(l1tokencreate.FieldIsFreezable, field.TypeBool, value)
		_node.IsFreezable = value
	}
	if value, ok := lcc.mutation.Network(); ok {
		_spec.SetField(l1tokencreate.FieldNetwork, field.TypeEnum, value)
		_node.Network = value
	}
	if value, ok := lcc.mutation.TokenIdentifier(); ok {
		_spec.SetField(l1tokencreate.FieldTokenIdentifier, field.TypeBytes, value)
		_node.TokenIdentifier = value
	}
	if value, ok := lcc.mutation.TransactionID(); ok {
		_spec.SetField(l1tokencreate.FieldTransactionID, field.TypeBytes, value)
		_node.TransactionID = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.L1TokenCreate.Create().
//		SetCreateTime(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.L1TokenCreateUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (lcc *L1TokenCreateCreate) OnConflict(opts ...sql.ConflictOption) *L1TokenCreateUpsertOne {
	lcc.conflict = opts
	return &L1TokenCreateUpsertOne{
		create: lcc,
	}
}

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

type (
	// L1TokenCreateUpsertOne is the builder for "upsert"-ing
	//  one L1TokenCreate node.
	L1TokenCreateUpsertOne struct {
		create *L1TokenCreateCreate
	}

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

// SetUpdateTime sets the "update_time" field.
func (u *L1TokenCreateUpsert) SetUpdateTime(v time.Time) *L1TokenCreateUpsert {
	u.Set(l1tokencreate.FieldUpdateTime, v)
	return u
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *L1TokenCreateUpsert) UpdateUpdateTime() *L1TokenCreateUpsert {
	u.SetExcluded(l1tokencreate.FieldUpdateTime)
	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.L1TokenCreate.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(l1tokencreate.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *L1TokenCreateUpsertOne) UpdateNewValues() *L1TokenCreateUpsertOne {
	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(l1tokencreate.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(l1tokencreate.FieldCreateTime)
		}
		if _, exists := u.create.mutation.IssuerPublicKey(); exists {
			s.SetIgnore(l1tokencreate.FieldIssuerPublicKey)
		}
		if _, exists := u.create.mutation.TokenName(); exists {
			s.SetIgnore(l1tokencreate.FieldTokenName)
		}
		if _, exists := u.create.mutation.TokenTicker(); exists {
			s.SetIgnore(l1tokencreate.FieldTokenTicker)
		}
		if _, exists := u.create.mutation.Decimals(); exists {
			s.SetIgnore(l1tokencreate.FieldDecimals)
		}
		if _, exists := u.create.mutation.MaxSupply(); exists {
			s.SetIgnore(l1tokencreate.FieldMaxSupply)
		}
		if _, exists := u.create.mutation.IsFreezable(); exists {
			s.SetIgnore(l1tokencreate.FieldIsFreezable)
		}
		if _, exists := u.create.mutation.Network(); exists {
			s.SetIgnore(l1tokencreate.FieldNetwork)
		}
		if _, exists := u.create.mutation.TokenIdentifier(); exists {
			s.SetIgnore(l1tokencreate.FieldTokenIdentifier)
		}
		if _, exists := u.create.mutation.TransactionID(); exists {
			s.SetIgnore(l1tokencreate.FieldTransactionID)
		}
	}))
	return u
}

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

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

// SetUpdateTime sets the "update_time" field.
func (u *L1TokenCreateUpsertOne) SetUpdateTime(v time.Time) *L1TokenCreateUpsertOne {
	return u.Update(func(s *L1TokenCreateUpsert) {
		s.SetUpdateTime(v)
	})
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *L1TokenCreateUpsertOne) UpdateUpdateTime() *L1TokenCreateUpsertOne {
	return u.Update(func(s *L1TokenCreateUpsert) {
		s.UpdateUpdateTime()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *L1TokenCreateUpsertOne) 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 *L1TokenCreateUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
	if u.create.driver.Dialect() == dialect.MySQL {
		// In case of "ON CONFLICT", there is no way to get back non-numeric ID
		// fields from the database since MySQL does not support the RETURNING clause.
		return id, errors.New("ent: L1TokenCreateUpsertOne.ID is not supported by MySQL driver. Use L1TokenCreateUpsertOne.Exec instead")
	}
	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 *L1TokenCreateUpsertOne) IDX(ctx context.Context) uuid.UUID {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.L1TokenCreate.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.L1TokenCreateUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (lccb *L1TokenCreateCreateBulk) OnConflict(opts ...sql.ConflictOption) *L1TokenCreateUpsertBulk {
	lccb.conflict = opts
	return &L1TokenCreateUpsertBulk{
		create: lccb,
	}
}

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

// L1TokenCreateUpsertBulk is the builder for "upsert"-ing
// a bulk of L1TokenCreate nodes.
type L1TokenCreateUpsertBulk struct {
	create *L1TokenCreateCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.L1TokenCreate.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(l1tokencreate.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *L1TokenCreateUpsertBulk) UpdateNewValues() *L1TokenCreateUpsertBulk {
	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(l1tokencreate.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(l1tokencreate.FieldCreateTime)
			}
			if _, exists := b.mutation.IssuerPublicKey(); exists {
				s.SetIgnore(l1tokencreate.FieldIssuerPublicKey)
			}
			if _, exists := b.mutation.TokenName(); exists {
				s.SetIgnore(l1tokencreate.FieldTokenName)
			}
			if _, exists := b.mutation.TokenTicker(); exists {
				s.SetIgnore(l1tokencreate.FieldTokenTicker)
			}
			if _, exists := b.mutation.Decimals(); exists {
				s.SetIgnore(l1tokencreate.FieldDecimals)
			}
			if _, exists := b.mutation.MaxSupply(); exists {
				s.SetIgnore(l1tokencreate.FieldMaxSupply)
			}
			if _, exists := b.mutation.IsFreezable(); exists {
				s.SetIgnore(l1tokencreate.FieldIsFreezable)
			}
			if _, exists := b.mutation.Network(); exists {
				s.SetIgnore(l1tokencreate.FieldNetwork)
			}
			if _, exists := b.mutation.TokenIdentifier(); exists {
				s.SetIgnore(l1tokencreate.FieldTokenIdentifier)
			}
			if _, exists := b.mutation.TransactionID(); exists {
				s.SetIgnore(l1tokencreate.FieldTransactionID)
			}
		}
	}))
	return u
}

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

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

// SetUpdateTime sets the "update_time" field.
func (u *L1TokenCreateUpsertBulk) SetUpdateTime(v time.Time) *L1TokenCreateUpsertBulk {
	return u.Update(func(s *L1TokenCreateUpsert) {
		s.SetUpdateTime(v)
	})
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *L1TokenCreateUpsertBulk) UpdateUpdateTime() *L1TokenCreateUpsertBulk {
	return u.Update(func(s *L1TokenCreateUpsert) {
		s.UpdateUpdateTime()
	})
}

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

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