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

// PreimageShareCreate is the builder for creating a PreimageShare entity.
type PreimageShareCreate struct {
	config
	mutation *PreimageShareMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetPaymentHash sets the "payment_hash" field.
func (psc *PreimageShareCreate) SetPaymentHash(b []byte) *PreimageShareCreate {
	psc.mutation.SetPaymentHash(b)
	return psc
}

// SetPreimageShare sets the "preimage_share" field.
func (psc *PreimageShareCreate) SetPreimageShare(b []byte) *PreimageShareCreate {
	psc.mutation.SetPreimageShare(b)
	return psc
}

// SetThreshold sets the "threshold" field.
func (psc *PreimageShareCreate) SetThreshold(i int32) *PreimageShareCreate {
	psc.mutation.SetThreshold(i)
	return psc
}

// SetOwnerIdentityPubkey sets the "owner_identity_pubkey" field.
func (psc *PreimageShareCreate) SetOwnerIdentityPubkey(k keys.Public) *PreimageShareCreate {
	psc.mutation.SetOwnerIdentityPubkey(k)
	return psc
}

// SetInvoiceString sets the "invoice_string" field.
func (psc *PreimageShareCreate) SetInvoiceString(s string) *PreimageShareCreate {
	psc.mutation.SetInvoiceString(s)
	return psc
}

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

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

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

// SetNillablePreimageRequestID sets the "preimage_request" edge to the PreimageRequest entity by ID if the given value is not nil.
func (psc *PreimageShareCreate) SetNillablePreimageRequestID(id *uuid.UUID) *PreimageShareCreate {
	if id != nil {
		psc = psc.SetPreimageRequestID(*id)
	}
	return psc
}

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

// Mutation returns the PreimageShareMutation object of the builder.
func (psc *PreimageShareCreate) Mutation() *PreimageShareMutation {
	return psc.mutation
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (psc *PreimageShareCreate) check() error {
	if _, ok := psc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "PreimageShare.create_time"`)}
	}
	if _, ok := psc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "PreimageShare.update_time"`)}
	}
	if _, ok := psc.mutation.PaymentHash(); !ok {
		return &ValidationError{Name: "payment_hash", err: errors.New(`ent: missing required field "PreimageShare.payment_hash"`)}
	}
	if v, ok := psc.mutation.PaymentHash(); ok {
		if err := preimageshare.PaymentHashValidator(v); err != nil {
			return &ValidationError{Name: "payment_hash", err: fmt.Errorf(`ent: validator failed for field "PreimageShare.payment_hash": %w`, err)}
		}
	}
	if _, ok := psc.mutation.PreimageShare(); !ok {
		return &ValidationError{Name: "preimage_share", err: errors.New(`ent: missing required field "PreimageShare.preimage_share"`)}
	}
	if v, ok := psc.mutation.PreimageShare(); ok {
		if err := preimageshare.PreimageShareValidator(v); err != nil {
			return &ValidationError{Name: "preimage_share", err: fmt.Errorf(`ent: validator failed for field "PreimageShare.preimage_share": %w`, err)}
		}
	}
	if _, ok := psc.mutation.Threshold(); !ok {
		return &ValidationError{Name: "threshold", err: errors.New(`ent: missing required field "PreimageShare.threshold"`)}
	}
	if _, ok := psc.mutation.OwnerIdentityPubkey(); !ok {
		return &ValidationError{Name: "owner_identity_pubkey", err: errors.New(`ent: missing required field "PreimageShare.owner_identity_pubkey"`)}
	}
	if _, ok := psc.mutation.InvoiceString(); !ok {
		return &ValidationError{Name: "invoice_string", err: errors.New(`ent: missing required field "PreimageShare.invoice_string"`)}
	}
	if v, ok := psc.mutation.InvoiceString(); ok {
		if err := preimageshare.InvoiceStringValidator(v); err != nil {
			return &ValidationError{Name: "invoice_string", err: fmt.Errorf(`ent: validator failed for field "PreimageShare.invoice_string": %w`, err)}
		}
	}
	return nil
}

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

func (psc *PreimageShareCreate) createSpec() (*PreimageShare, *sqlgraph.CreateSpec) {
	var (
		_node = &PreimageShare{config: psc.config}
		_spec = sqlgraph.NewCreateSpec(preimageshare.Table, sqlgraph.NewFieldSpec(preimageshare.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = psc.conflict
	if id, ok := psc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := psc.mutation.CreateTime(); ok {
		_spec.SetField(preimageshare.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := psc.mutation.UpdateTime(); ok {
		_spec.SetField(preimageshare.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := psc.mutation.PaymentHash(); ok {
		_spec.SetField(preimageshare.FieldPaymentHash, field.TypeBytes, value)
		_node.PaymentHash = value
	}
	if value, ok := psc.mutation.PreimageShare(); ok {
		_spec.SetField(preimageshare.FieldPreimageShare, field.TypeBytes, value)
		_node.PreimageShare = value
	}
	if value, ok := psc.mutation.Threshold(); ok {
		_spec.SetField(preimageshare.FieldThreshold, field.TypeInt32, value)
		_node.Threshold = value
	}
	if value, ok := psc.mutation.OwnerIdentityPubkey(); ok {
		_spec.SetField(preimageshare.FieldOwnerIdentityPubkey, field.TypeBytes, value)
		_node.OwnerIdentityPubkey = value
	}
	if value, ok := psc.mutation.InvoiceString(); ok {
		_spec.SetField(preimageshare.FieldInvoiceString, field.TypeString, value)
		_node.InvoiceString = value
	}
	if nodes := psc.mutation.PreimageRequestIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   preimageshare.PreimageRequestTable,
			Columns: []string{preimageshare.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.preimage_request_preimage_shares = &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.PreimageShare.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.PreimageShareUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (psc *PreimageShareCreate) OnConflict(opts ...sql.ConflictOption) *PreimageShareUpsertOne {
	psc.conflict = opts
	return &PreimageShareUpsertOne{
		create: psc,
	}
}

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

type (
	// PreimageShareUpsertOne is the builder for "upsert"-ing
	//  one PreimageShare node.
	PreimageShareUpsertOne struct {
		create *PreimageShareCreate
	}

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

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

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *PreimageShareUpsert) UpdateUpdateTime() *PreimageShareUpsert {
	u.SetExcluded(preimageshare.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.PreimageShare.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(preimageshare.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *PreimageShareUpsertOne) UpdateNewValues() *PreimageShareUpsertOne {
	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(preimageshare.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(preimageshare.FieldCreateTime)
		}
		if _, exists := u.create.mutation.PaymentHash(); exists {
			s.SetIgnore(preimageshare.FieldPaymentHash)
		}
		if _, exists := u.create.mutation.PreimageShare(); exists {
			s.SetIgnore(preimageshare.FieldPreimageShare)
		}
		if _, exists := u.create.mutation.Threshold(); exists {
			s.SetIgnore(preimageshare.FieldThreshold)
		}
		if _, exists := u.create.mutation.OwnerIdentityPubkey(); exists {
			s.SetIgnore(preimageshare.FieldOwnerIdentityPubkey)
		}
		if _, exists := u.create.mutation.InvoiceString(); exists {
			s.SetIgnore(preimageshare.FieldInvoiceString)
		}
	}))
	return u
}

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

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

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

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

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

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

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

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

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

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

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

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

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

// PreimageShareUpsertBulk is the builder for "upsert"-ing
// a bulk of PreimageShare nodes.
type PreimageShareUpsertBulk struct {
	create *PreimageShareCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.PreimageShare.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(preimageshare.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *PreimageShareUpsertBulk) UpdateNewValues() *PreimageShareUpsertBulk {
	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(preimageshare.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(preimageshare.FieldCreateTime)
			}
			if _, exists := b.mutation.PaymentHash(); exists {
				s.SetIgnore(preimageshare.FieldPaymentHash)
			}
			if _, exists := b.mutation.PreimageShare(); exists {
				s.SetIgnore(preimageshare.FieldPreimageShare)
			}
			if _, exists := b.mutation.Threshold(); exists {
				s.SetIgnore(preimageshare.FieldThreshold)
			}
			if _, exists := b.mutation.OwnerIdentityPubkey(); exists {
				s.SetIgnore(preimageshare.FieldOwnerIdentityPubkey)
			}
			if _, exists := b.mutation.InvoiceString(); exists {
				s.SetIgnore(preimageshare.FieldInvoiceString)
			}
		}
	}))
	return u
}

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

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

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

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

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

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