// 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/preimagerequest"
	"github.com/lightsparkdev/spark/so/ent/treenode"
	"github.com/lightsparkdev/spark/so/ent/usersignedtransaction"
)

// UserSignedTransactionCreate is the builder for creating a UserSignedTransaction entity.
type UserSignedTransactionCreate struct {
	config
	mutation *UserSignedTransactionMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetTransaction sets the "transaction" field.
func (ustc *UserSignedTransactionCreate) SetTransaction(b []byte) *UserSignedTransactionCreate {
	ustc.mutation.SetTransaction(b)
	return ustc
}

// SetUserSignature sets the "user_signature" field.
func (ustc *UserSignedTransactionCreate) SetUserSignature(b []byte) *UserSignedTransactionCreate {
	ustc.mutation.SetUserSignature(b)
	return ustc
}

// SetSigningCommitments sets the "signing_commitments" field.
func (ustc *UserSignedTransactionCreate) SetSigningCommitments(b []byte) *UserSignedTransactionCreate {
	ustc.mutation.SetSigningCommitments(b)
	return ustc
}

// SetUserSignatureCommitment sets the "user_signature_commitment" field.
func (ustc *UserSignedTransactionCreate) SetUserSignatureCommitment(b []byte) *UserSignedTransactionCreate {
	ustc.mutation.SetUserSignatureCommitment(b)
	return ustc
}

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

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

// SetTreeNodeID sets the "tree_node" edge to the TreeNode entity by ID.
func (ustc *UserSignedTransactionCreate) SetTreeNodeID(id uuid.UUID) *UserSignedTransactionCreate {
	ustc.mutation.SetTreeNodeID(id)
	return ustc
}

// SetTreeNode sets the "tree_node" edge to the TreeNode entity.
func (ustc *UserSignedTransactionCreate) SetTreeNode(t *TreeNode) *UserSignedTransactionCreate {
	return ustc.SetTreeNodeID(t.ID)
}

// SetPreimageRequestID sets the "preimage_request" edge to the PreimageRequest entity by ID.
func (ustc *UserSignedTransactionCreate) SetPreimageRequestID(id uuid.UUID) *UserSignedTransactionCreate {
	ustc.mutation.SetPreimageRequestID(id)
	return ustc
}

// SetPreimageRequest sets the "preimage_request" edge to the PreimageRequest entity.
func (ustc *UserSignedTransactionCreate) SetPreimageRequest(p *PreimageRequest) *UserSignedTransactionCreate {
	return ustc.SetPreimageRequestID(p.ID)
}

// Mutation returns the UserSignedTransactionMutation object of the builder.
func (ustc *UserSignedTransactionCreate) Mutation() *UserSignedTransactionMutation {
	return ustc.mutation
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (ustc *UserSignedTransactionCreate) check() error {
	if _, ok := ustc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "UserSignedTransaction.create_time"`)}
	}
	if _, ok := ustc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "UserSignedTransaction.update_time"`)}
	}
	if _, ok := ustc.mutation.Transaction(); !ok {
		return &ValidationError{Name: "transaction", err: errors.New(`ent: missing required field "UserSignedTransaction.transaction"`)}
	}
	if v, ok := ustc.mutation.Transaction(); ok {
		if err := usersignedtransaction.TransactionValidator(v); err != nil {
			return &ValidationError{Name: "transaction", err: fmt.Errorf(`ent: validator failed for field "UserSignedTransaction.transaction": %w`, err)}
		}
	}
	if _, ok := ustc.mutation.UserSignature(); !ok {
		return &ValidationError{Name: "user_signature", err: errors.New(`ent: missing required field "UserSignedTransaction.user_signature"`)}
	}
	if v, ok := ustc.mutation.UserSignature(); ok {
		if err := usersignedtransaction.UserSignatureValidator(v); err != nil {
			return &ValidationError{Name: "user_signature", err: fmt.Errorf(`ent: validator failed for field "UserSignedTransaction.user_signature": %w`, err)}
		}
	}
	if _, ok := ustc.mutation.SigningCommitments(); !ok {
		return &ValidationError{Name: "signing_commitments", err: errors.New(`ent: missing required field "UserSignedTransaction.signing_commitments"`)}
	}
	if v, ok := ustc.mutation.SigningCommitments(); ok {
		if err := usersignedtransaction.SigningCommitmentsValidator(v); err != nil {
			return &ValidationError{Name: "signing_commitments", err: fmt.Errorf(`ent: validator failed for field "UserSignedTransaction.signing_commitments": %w`, err)}
		}
	}
	if _, ok := ustc.mutation.UserSignatureCommitment(); !ok {
		return &ValidationError{Name: "user_signature_commitment", err: errors.New(`ent: missing required field "UserSignedTransaction.user_signature_commitment"`)}
	}
	if v, ok := ustc.mutation.UserSignatureCommitment(); ok {
		if err := usersignedtransaction.UserSignatureCommitmentValidator(v); err != nil {
			return &ValidationError{Name: "user_signature_commitment", err: fmt.Errorf(`ent: validator failed for field "UserSignedTransaction.user_signature_commitment": %w`, err)}
		}
	}
	if len(ustc.mutation.TreeNodeIDs()) == 0 {
		return &ValidationError{Name: "tree_node", err: errors.New(`ent: missing required edge "UserSignedTransaction.tree_node"`)}
	}
	if len(ustc.mutation.PreimageRequestIDs()) == 0 {
		return &ValidationError{Name: "preimage_request", err: errors.New(`ent: missing required edge "UserSignedTransaction.preimage_request"`)}
	}
	return nil
}

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

func (ustc *UserSignedTransactionCreate) createSpec() (*UserSignedTransaction, *sqlgraph.CreateSpec) {
	var (
		_node = &UserSignedTransaction{config: ustc.config}
		_spec = sqlgraph.NewCreateSpec(usersignedtransaction.Table, sqlgraph.NewFieldSpec(usersignedtransaction.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = ustc.conflict
	if id, ok := ustc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := ustc.mutation.CreateTime(); ok {
		_spec.SetField(usersignedtransaction.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := ustc.mutation.UpdateTime(); ok {
		_spec.SetField(usersignedtransaction.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := ustc.mutation.Transaction(); ok {
		_spec.SetField(usersignedtransaction.FieldTransaction, field.TypeBytes, value)
		_node.Transaction = value
	}
	if value, ok := ustc.mutation.UserSignature(); ok {
		_spec.SetField(usersignedtransaction.FieldUserSignature, field.TypeBytes, value)
		_node.UserSignature = value
	}
	if value, ok := ustc.mutation.SigningCommitments(); ok {
		_spec.SetField(usersignedtransaction.FieldSigningCommitments, field.TypeBytes, value)
		_node.SigningCommitments = value
	}
	if value, ok := ustc.mutation.UserSignatureCommitment(); ok {
		_spec.SetField(usersignedtransaction.FieldUserSignatureCommitment, field.TypeBytes, value)
		_node.UserSignatureCommitment = value
	}
	if nodes := ustc.mutation.TreeNodeIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   usersignedtransaction.TreeNodeTable,
			Columns: []string{usersignedtransaction.TreeNodeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(treenode.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.user_signed_transaction_tree_node = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ustc.mutation.PreimageRequestIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   usersignedtransaction.PreimageRequestTable,
			Columns: []string{usersignedtransaction.PreimageRequestColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(preimagerequest.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.user_signed_transaction_preimage_request = &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.UserSignedTransaction.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.UserSignedTransactionUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (ustc *UserSignedTransactionCreate) OnConflict(opts ...sql.ConflictOption) *UserSignedTransactionUpsertOne {
	ustc.conflict = opts
	return &UserSignedTransactionUpsertOne{
		create: ustc,
	}
}

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

type (
	// UserSignedTransactionUpsertOne is the builder for "upsert"-ing
	//  one UserSignedTransaction node.
	UserSignedTransactionUpsertOne struct {
		create *UserSignedTransactionCreate
	}

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

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

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *UserSignedTransactionUpsert) UpdateUpdateTime() *UserSignedTransactionUpsert {
	u.SetExcluded(usersignedtransaction.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.UserSignedTransaction.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(usersignedtransaction.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UserSignedTransactionUpsertOne) UpdateNewValues() *UserSignedTransactionUpsertOne {
	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(usersignedtransaction.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(usersignedtransaction.FieldCreateTime)
		}
		if _, exists := u.create.mutation.Transaction(); exists {
			s.SetIgnore(usersignedtransaction.FieldTransaction)
		}
		if _, exists := u.create.mutation.UserSignature(); exists {
			s.SetIgnore(usersignedtransaction.FieldUserSignature)
		}
		if _, exists := u.create.mutation.SigningCommitments(); exists {
			s.SetIgnore(usersignedtransaction.FieldSigningCommitments)
		}
		if _, exists := u.create.mutation.UserSignatureCommitment(); exists {
			s.SetIgnore(usersignedtransaction.FieldUserSignatureCommitment)
		}
	}))
	return u
}

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

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

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

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

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

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

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

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

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

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

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

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

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

// UserSignedTransactionUpsertBulk is the builder for "upsert"-ing
// a bulk of UserSignedTransaction nodes.
type UserSignedTransactionUpsertBulk struct {
	create *UserSignedTransactionCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.UserSignedTransaction.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(usersignedtransaction.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UserSignedTransactionUpsertBulk) UpdateNewValues() *UserSignedTransactionUpsertBulk {
	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(usersignedtransaction.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(usersignedtransaction.FieldCreateTime)
			}
			if _, exists := b.mutation.Transaction(); exists {
				s.SetIgnore(usersignedtransaction.FieldTransaction)
			}
			if _, exists := b.mutation.UserSignature(); exists {
				s.SetIgnore(usersignedtransaction.FieldUserSignature)
			}
			if _, exists := b.mutation.SigningCommitments(); exists {
				s.SetIgnore(usersignedtransaction.FieldSigningCommitments)
			}
			if _, exists := b.mutation.UserSignatureCommitment(); exists {
				s.SetIgnore(usersignedtransaction.FieldUserSignatureCommitment)
			}
		}
	}))
	return u
}

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

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

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

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

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

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