// 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/so/ent/depositaddress"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
	"github.com/lightsparkdev/spark/so/ent/utxo"
)

// UtxoCreate is the builder for creating a Utxo entity.
type UtxoCreate struct {
	config
	mutation *UtxoMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetBlockHeight sets the "block_height" field.
func (uc *UtxoCreate) SetBlockHeight(i int64) *UtxoCreate {
	uc.mutation.SetBlockHeight(i)
	return uc
}

// SetTxid sets the "txid" field.
func (uc *UtxoCreate) SetTxid(b []byte) *UtxoCreate {
	uc.mutation.SetTxid(b)
	return uc
}

// SetVout sets the "vout" field.
func (uc *UtxoCreate) SetVout(u uint32) *UtxoCreate {
	uc.mutation.SetVout(u)
	return uc
}

// SetAmount sets the "amount" field.
func (uc *UtxoCreate) SetAmount(u uint64) *UtxoCreate {
	uc.mutation.SetAmount(u)
	return uc
}

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

// SetPkScript sets the "pk_script" field.
func (uc *UtxoCreate) SetPkScript(b []byte) *UtxoCreate {
	uc.mutation.SetPkScript(b)
	return uc
}

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

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

// SetDepositAddressID sets the "deposit_address" edge to the DepositAddress entity by ID.
func (uc *UtxoCreate) SetDepositAddressID(id uuid.UUID) *UtxoCreate {
	uc.mutation.SetDepositAddressID(id)
	return uc
}

// SetDepositAddress sets the "deposit_address" edge to the DepositAddress entity.
func (uc *UtxoCreate) SetDepositAddress(d *DepositAddress) *UtxoCreate {
	return uc.SetDepositAddressID(d.ID)
}

// Mutation returns the UtxoMutation object of the builder.
func (uc *UtxoCreate) Mutation() *UtxoMutation {
	return uc.mutation
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (uc *UtxoCreate) check() error {
	if _, ok := uc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "Utxo.create_time"`)}
	}
	if _, ok := uc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "Utxo.update_time"`)}
	}
	if _, ok := uc.mutation.BlockHeight(); !ok {
		return &ValidationError{Name: "block_height", err: errors.New(`ent: missing required field "Utxo.block_height"`)}
	}
	if _, ok := uc.mutation.Txid(); !ok {
		return &ValidationError{Name: "txid", err: errors.New(`ent: missing required field "Utxo.txid"`)}
	}
	if v, ok := uc.mutation.Txid(); ok {
		if err := utxo.TxidValidator(v); err != nil {
			return &ValidationError{Name: "txid", err: fmt.Errorf(`ent: validator failed for field "Utxo.txid": %w`, err)}
		}
	}
	if _, ok := uc.mutation.Vout(); !ok {
		return &ValidationError{Name: "vout", err: errors.New(`ent: missing required field "Utxo.vout"`)}
	}
	if _, ok := uc.mutation.Amount(); !ok {
		return &ValidationError{Name: "amount", err: errors.New(`ent: missing required field "Utxo.amount"`)}
	}
	if _, ok := uc.mutation.Network(); !ok {
		return &ValidationError{Name: "network", err: errors.New(`ent: missing required field "Utxo.network"`)}
	}
	if v, ok := uc.mutation.Network(); ok {
		if err := utxo.NetworkValidator(v); err != nil {
			return &ValidationError{Name: "network", err: fmt.Errorf(`ent: validator failed for field "Utxo.network": %w`, err)}
		}
	}
	if _, ok := uc.mutation.PkScript(); !ok {
		return &ValidationError{Name: "pk_script", err: errors.New(`ent: missing required field "Utxo.pk_script"`)}
	}
	if len(uc.mutation.DepositAddressIDs()) == 0 {
		return &ValidationError{Name: "deposit_address", err: errors.New(`ent: missing required edge "Utxo.deposit_address"`)}
	}
	return nil
}

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

func (uc *UtxoCreate) createSpec() (*Utxo, *sqlgraph.CreateSpec) {
	var (
		_node = &Utxo{config: uc.config}
		_spec = sqlgraph.NewCreateSpec(utxo.Table, sqlgraph.NewFieldSpec(utxo.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = uc.conflict
	if id, ok := uc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := uc.mutation.CreateTime(); ok {
		_spec.SetField(utxo.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := uc.mutation.UpdateTime(); ok {
		_spec.SetField(utxo.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := uc.mutation.BlockHeight(); ok {
		_spec.SetField(utxo.FieldBlockHeight, field.TypeInt64, value)
		_node.BlockHeight = value
	}
	if value, ok := uc.mutation.Txid(); ok {
		_spec.SetField(utxo.FieldTxid, field.TypeBytes, value)
		_node.Txid = value
	}
	if value, ok := uc.mutation.Vout(); ok {
		_spec.SetField(utxo.FieldVout, field.TypeUint32, value)
		_node.Vout = value
	}
	if value, ok := uc.mutation.Amount(); ok {
		_spec.SetField(utxo.FieldAmount, field.TypeUint64, value)
		_node.Amount = value
	}
	if value, ok := uc.mutation.Network(); ok {
		_spec.SetField(utxo.FieldNetwork, field.TypeEnum, value)
		_node.Network = value
	}
	if value, ok := uc.mutation.PkScript(); ok {
		_spec.SetField(utxo.FieldPkScript, field.TypeBytes, value)
		_node.PkScript = value
	}
	if nodes := uc.mutation.DepositAddressIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   utxo.DepositAddressTable,
			Columns: []string{utxo.DepositAddressColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(depositaddress.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.deposit_address_utxo = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

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

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

type (
	// UtxoUpsertOne is the builder for "upsert"-ing
	//  one Utxo node.
	UtxoUpsertOne struct {
		create *UtxoCreate
	}

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

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

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

// SetBlockHeight sets the "block_height" field.
func (u *UtxoUpsert) SetBlockHeight(v int64) *UtxoUpsert {
	u.Set(utxo.FieldBlockHeight, v)
	return u
}

// UpdateBlockHeight sets the "block_height" field to the value that was provided on create.
func (u *UtxoUpsert) UpdateBlockHeight() *UtxoUpsert {
	u.SetExcluded(utxo.FieldBlockHeight)
	return u
}

// AddBlockHeight adds v to the "block_height" field.
func (u *UtxoUpsert) AddBlockHeight(v int64) *UtxoUpsert {
	u.Add(utxo.FieldBlockHeight, v)
	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.Utxo.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(utxo.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UtxoUpsertOne) UpdateNewValues() *UtxoUpsertOne {
	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(utxo.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(utxo.FieldCreateTime)
		}
		if _, exists := u.create.mutation.Txid(); exists {
			s.SetIgnore(utxo.FieldTxid)
		}
		if _, exists := u.create.mutation.Vout(); exists {
			s.SetIgnore(utxo.FieldVout)
		}
		if _, exists := u.create.mutation.Amount(); exists {
			s.SetIgnore(utxo.FieldAmount)
		}
		if _, exists := u.create.mutation.Network(); exists {
			s.SetIgnore(utxo.FieldNetwork)
		}
		if _, exists := u.create.mutation.PkScript(); exists {
			s.SetIgnore(utxo.FieldPkScript)
		}
	}))
	return u
}

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

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

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

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

// SetBlockHeight sets the "block_height" field.
func (u *UtxoUpsertOne) SetBlockHeight(v int64) *UtxoUpsertOne {
	return u.Update(func(s *UtxoUpsert) {
		s.SetBlockHeight(v)
	})
}

// AddBlockHeight adds v to the "block_height" field.
func (u *UtxoUpsertOne) AddBlockHeight(v int64) *UtxoUpsertOne {
	return u.Update(func(s *UtxoUpsert) {
		s.AddBlockHeight(v)
	})
}

// UpdateBlockHeight sets the "block_height" field to the value that was provided on create.
func (u *UtxoUpsertOne) UpdateBlockHeight() *UtxoUpsertOne {
	return u.Update(func(s *UtxoUpsert) {
		s.UpdateBlockHeight()
	})
}

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

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

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

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

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

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

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

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

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

// UtxoUpsertBulk is the builder for "upsert"-ing
// a bulk of Utxo nodes.
type UtxoUpsertBulk struct {
	create *UtxoCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.Utxo.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(utxo.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UtxoUpsertBulk) UpdateNewValues() *UtxoUpsertBulk {
	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(utxo.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(utxo.FieldCreateTime)
			}
			if _, exists := b.mutation.Txid(); exists {
				s.SetIgnore(utxo.FieldTxid)
			}
			if _, exists := b.mutation.Vout(); exists {
				s.SetIgnore(utxo.FieldVout)
			}
			if _, exists := b.mutation.Amount(); exists {
				s.SetIgnore(utxo.FieldAmount)
			}
			if _, exists := b.mutation.Network(); exists {
				s.SetIgnore(utxo.FieldNetwork)
			}
			if _, exists := b.mutation.PkScript(); exists {
				s.SetIgnore(utxo.FieldPkScript)
			}
		}
	}))
	return u
}

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

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

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

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

// SetBlockHeight sets the "block_height" field.
func (u *UtxoUpsertBulk) SetBlockHeight(v int64) *UtxoUpsertBulk {
	return u.Update(func(s *UtxoUpsert) {
		s.SetBlockHeight(v)
	})
}

// AddBlockHeight adds v to the "block_height" field.
func (u *UtxoUpsertBulk) AddBlockHeight(v int64) *UtxoUpsertBulk {
	return u.Update(func(s *UtxoUpsert) {
		s.AddBlockHeight(v)
	})
}

// UpdateBlockHeight sets the "block_height" field to the value that was provided on create.
func (u *UtxoUpsertBulk) UpdateBlockHeight() *UtxoUpsertBulk {
	return u.Update(func(s *UtxoUpsert) {
		s.UpdateBlockHeight()
	})
}

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

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