// 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/tokenmint"
	"github.com/lightsparkdev/spark/so/ent/tokentransaction"
)

// TokenMintCreate is the builder for creating a TokenMint entity.
type TokenMintCreate struct {
	config
	mutation *TokenMintMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

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

// SetWalletProvidedTimestamp sets the "wallet_provided_timestamp" field.
func (tmc *TokenMintCreate) SetWalletProvidedTimestamp(u uint64) *TokenMintCreate {
	tmc.mutation.SetWalletProvidedTimestamp(u)
	return tmc
}

// SetIssuerSignature sets the "issuer_signature" field.
func (tmc *TokenMintCreate) SetIssuerSignature(b []byte) *TokenMintCreate {
	tmc.mutation.SetIssuerSignature(b)
	return tmc
}

// SetOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field.
func (tmc *TokenMintCreate) SetOperatorSpecificIssuerSignature(b []byte) *TokenMintCreate {
	tmc.mutation.SetOperatorSpecificIssuerSignature(b)
	return tmc
}

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

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

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

// AddTokenTransactionIDs adds the "token_transaction" edge to the TokenTransaction entity by IDs.
func (tmc *TokenMintCreate) AddTokenTransactionIDs(ids ...uuid.UUID) *TokenMintCreate {
	tmc.mutation.AddTokenTransactionIDs(ids...)
	return tmc
}

// AddTokenTransaction adds the "token_transaction" edges to the TokenTransaction entity.
func (tmc *TokenMintCreate) AddTokenTransaction(t ...*TokenTransaction) *TokenMintCreate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return tmc.AddTokenTransactionIDs(ids...)
}

// Mutation returns the TokenMintMutation object of the builder.
func (tmc *TokenMintCreate) Mutation() *TokenMintMutation {
	return tmc.mutation
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (tmc *TokenMintCreate) check() error {
	if _, ok := tmc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "TokenMint.create_time"`)}
	}
	if _, ok := tmc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "TokenMint.update_time"`)}
	}
	if _, ok := tmc.mutation.IssuerPublicKey(); !ok {
		return &ValidationError{Name: "issuer_public_key", err: errors.New(`ent: missing required field "TokenMint.issuer_public_key"`)}
	}
	if _, ok := tmc.mutation.WalletProvidedTimestamp(); !ok {
		return &ValidationError{Name: "wallet_provided_timestamp", err: errors.New(`ent: missing required field "TokenMint.wallet_provided_timestamp"`)}
	}
	if _, ok := tmc.mutation.IssuerSignature(); !ok {
		return &ValidationError{Name: "issuer_signature", err: errors.New(`ent: missing required field "TokenMint.issuer_signature"`)}
	}
	if v, ok := tmc.mutation.IssuerSignature(); ok {
		if err := tokenmint.IssuerSignatureValidator(v); err != nil {
			return &ValidationError{Name: "issuer_signature", err: fmt.Errorf(`ent: validator failed for field "TokenMint.issuer_signature": %w`, err)}
		}
	}
	return nil
}

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

func (tmc *TokenMintCreate) createSpec() (*TokenMint, *sqlgraph.CreateSpec) {
	var (
		_node = &TokenMint{config: tmc.config}
		_spec = sqlgraph.NewCreateSpec(tokenmint.Table, sqlgraph.NewFieldSpec(tokenmint.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = tmc.conflict
	if id, ok := tmc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := tmc.mutation.CreateTime(); ok {
		_spec.SetField(tokenmint.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := tmc.mutation.UpdateTime(); ok {
		_spec.SetField(tokenmint.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := tmc.mutation.IssuerPublicKey(); ok {
		_spec.SetField(tokenmint.FieldIssuerPublicKey, field.TypeBytes, value)
		_node.IssuerPublicKey = value
	}
	if value, ok := tmc.mutation.WalletProvidedTimestamp(); ok {
		_spec.SetField(tokenmint.FieldWalletProvidedTimestamp, field.TypeUint64, value)
		_node.WalletProvidedTimestamp = value
	}
	if value, ok := tmc.mutation.IssuerSignature(); ok {
		_spec.SetField(tokenmint.FieldIssuerSignature, field.TypeBytes, value)
		_node.IssuerSignature = value
	}
	if value, ok := tmc.mutation.OperatorSpecificIssuerSignature(); ok {
		_spec.SetField(tokenmint.FieldOperatorSpecificIssuerSignature, field.TypeBytes, value)
		_node.OperatorSpecificIssuerSignature = value
	}
	if value, ok := tmc.mutation.TokenIdentifier(); ok {
		_spec.SetField(tokenmint.FieldTokenIdentifier, field.TypeBytes, value)
		_node.TokenIdentifier = value
	}
	if nodes := tmc.mutation.TokenTransactionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   tokenmint.TokenTransactionTable,
			Columns: []string{tokenmint.TokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_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.TokenMint.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.TokenMintUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (tmc *TokenMintCreate) OnConflict(opts ...sql.ConflictOption) *TokenMintUpsertOne {
	tmc.conflict = opts
	return &TokenMintUpsertOne{
		create: tmc,
	}
}

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

type (
	// TokenMintUpsertOne is the builder for "upsert"-ing
	//  one TokenMint node.
	TokenMintUpsertOne struct {
		create *TokenMintCreate
	}

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

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

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *TokenMintUpsert) UpdateUpdateTime() *TokenMintUpsert {
	u.SetExcluded(tokenmint.FieldUpdateTime)
	return u
}

// SetOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field.
func (u *TokenMintUpsert) SetOperatorSpecificIssuerSignature(v []byte) *TokenMintUpsert {
	u.Set(tokenmint.FieldOperatorSpecificIssuerSignature, v)
	return u
}

// UpdateOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field to the value that was provided on create.
func (u *TokenMintUpsert) UpdateOperatorSpecificIssuerSignature() *TokenMintUpsert {
	u.SetExcluded(tokenmint.FieldOperatorSpecificIssuerSignature)
	return u
}

// ClearOperatorSpecificIssuerSignature clears the value of the "operator_specific_issuer_signature" field.
func (u *TokenMintUpsert) ClearOperatorSpecificIssuerSignature() *TokenMintUpsert {
	u.SetNull(tokenmint.FieldOperatorSpecificIssuerSignature)
	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.TokenMint.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(tokenmint.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *TokenMintUpsertOne) UpdateNewValues() *TokenMintUpsertOne {
	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(tokenmint.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(tokenmint.FieldCreateTime)
		}
		if _, exists := u.create.mutation.IssuerPublicKey(); exists {
			s.SetIgnore(tokenmint.FieldIssuerPublicKey)
		}
		if _, exists := u.create.mutation.WalletProvidedTimestamp(); exists {
			s.SetIgnore(tokenmint.FieldWalletProvidedTimestamp)
		}
		if _, exists := u.create.mutation.IssuerSignature(); exists {
			s.SetIgnore(tokenmint.FieldIssuerSignature)
		}
		if _, exists := u.create.mutation.TokenIdentifier(); exists {
			s.SetIgnore(tokenmint.FieldTokenIdentifier)
		}
	}))
	return u
}

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

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

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

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

// SetOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field.
func (u *TokenMintUpsertOne) SetOperatorSpecificIssuerSignature(v []byte) *TokenMintUpsertOne {
	return u.Update(func(s *TokenMintUpsert) {
		s.SetOperatorSpecificIssuerSignature(v)
	})
}

// UpdateOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field to the value that was provided on create.
func (u *TokenMintUpsertOne) UpdateOperatorSpecificIssuerSignature() *TokenMintUpsertOne {
	return u.Update(func(s *TokenMintUpsert) {
		s.UpdateOperatorSpecificIssuerSignature()
	})
}

// ClearOperatorSpecificIssuerSignature clears the value of the "operator_specific_issuer_signature" field.
func (u *TokenMintUpsertOne) ClearOperatorSpecificIssuerSignature() *TokenMintUpsertOne {
	return u.Update(func(s *TokenMintUpsert) {
		s.ClearOperatorSpecificIssuerSignature()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *TokenMintUpsertOne) 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 *TokenMintUpsertOne) 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: TokenMintUpsertOne.ID is not supported by MySQL driver. Use TokenMintUpsertOne.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 *TokenMintUpsertOne) IDX(ctx context.Context) uuid.UUID {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

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

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

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

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

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

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

// TokenMintUpsertBulk is the builder for "upsert"-ing
// a bulk of TokenMint nodes.
type TokenMintUpsertBulk struct {
	create *TokenMintCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.TokenMint.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(tokenmint.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *TokenMintUpsertBulk) UpdateNewValues() *TokenMintUpsertBulk {
	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(tokenmint.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(tokenmint.FieldCreateTime)
			}
			if _, exists := b.mutation.IssuerPublicKey(); exists {
				s.SetIgnore(tokenmint.FieldIssuerPublicKey)
			}
			if _, exists := b.mutation.WalletProvidedTimestamp(); exists {
				s.SetIgnore(tokenmint.FieldWalletProvidedTimestamp)
			}
			if _, exists := b.mutation.IssuerSignature(); exists {
				s.SetIgnore(tokenmint.FieldIssuerSignature)
			}
			if _, exists := b.mutation.TokenIdentifier(); exists {
				s.SetIgnore(tokenmint.FieldTokenIdentifier)
			}
		}
	}))
	return u
}

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

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

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

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

// SetOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field.
func (u *TokenMintUpsertBulk) SetOperatorSpecificIssuerSignature(v []byte) *TokenMintUpsertBulk {
	return u.Update(func(s *TokenMintUpsert) {
		s.SetOperatorSpecificIssuerSignature(v)
	})
}

// UpdateOperatorSpecificIssuerSignature sets the "operator_specific_issuer_signature" field to the value that was provided on create.
func (u *TokenMintUpsertBulk) UpdateOperatorSpecificIssuerSignature() *TokenMintUpsertBulk {
	return u.Update(func(s *TokenMintUpsert) {
		s.UpdateOperatorSpecificIssuerSignature()
	})
}

// ClearOperatorSpecificIssuerSignature clears the value of the "operator_specific_issuer_signature" field.
func (u *TokenMintUpsertBulk) ClearOperatorSpecificIssuerSignature() *TokenMintUpsertBulk {
	return u.Update(func(s *TokenMintUpsert) {
		s.ClearOperatorSpecificIssuerSignature()
	})
}

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

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