// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UtxoSwapUpdate is the builder for updating UtxoSwap entities.
type UtxoSwapUpdate struct {
	config
	hooks    []Hook
	mutation *UtxoSwapMutation
}

// Where appends a list predicates to the UtxoSwapUpdate builder.
func (usu *UtxoSwapUpdate) Where(ps ...predicate.UtxoSwap) *UtxoSwapUpdate {
	usu.mutation.Where(ps...)
	return usu
}

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

// SetStatus sets the "status" field.
func (usu *UtxoSwapUpdate) SetStatus(sss schematype.UtxoSwapStatus) *UtxoSwapUpdate {
	usu.mutation.SetStatus(sss)
	return usu
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableStatus(sss *schematype.UtxoSwapStatus) *UtxoSwapUpdate {
	if sss != nil {
		usu.SetStatus(*sss)
	}
	return usu
}

// SetRequestType sets the "request_type" field.
func (usu *UtxoSwapUpdate) SetRequestType(ssrt schematype.UtxoSwapRequestType) *UtxoSwapUpdate {
	usu.mutation.SetRequestType(ssrt)
	return usu
}

// SetNillableRequestType sets the "request_type" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableRequestType(ssrt *schematype.UtxoSwapRequestType) *UtxoSwapUpdate {
	if ssrt != nil {
		usu.SetRequestType(*ssrt)
	}
	return usu
}

// SetCreditAmountSats sets the "credit_amount_sats" field.
func (usu *UtxoSwapUpdate) SetCreditAmountSats(u uint64) *UtxoSwapUpdate {
	usu.mutation.ResetCreditAmountSats()
	usu.mutation.SetCreditAmountSats(u)
	return usu
}

// SetNillableCreditAmountSats sets the "credit_amount_sats" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableCreditAmountSats(u *uint64) *UtxoSwapUpdate {
	if u != nil {
		usu.SetCreditAmountSats(*u)
	}
	return usu
}

// AddCreditAmountSats adds u to the "credit_amount_sats" field.
func (usu *UtxoSwapUpdate) AddCreditAmountSats(u int64) *UtxoSwapUpdate {
	usu.mutation.AddCreditAmountSats(u)
	return usu
}

// ClearCreditAmountSats clears the value of the "credit_amount_sats" field.
func (usu *UtxoSwapUpdate) ClearCreditAmountSats() *UtxoSwapUpdate {
	usu.mutation.ClearCreditAmountSats()
	return usu
}

// SetMaxFeeSats sets the "max_fee_sats" field.
func (usu *UtxoSwapUpdate) SetMaxFeeSats(u uint64) *UtxoSwapUpdate {
	usu.mutation.ResetMaxFeeSats()
	usu.mutation.SetMaxFeeSats(u)
	return usu
}

// SetNillableMaxFeeSats sets the "max_fee_sats" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableMaxFeeSats(u *uint64) *UtxoSwapUpdate {
	if u != nil {
		usu.SetMaxFeeSats(*u)
	}
	return usu
}

// AddMaxFeeSats adds u to the "max_fee_sats" field.
func (usu *UtxoSwapUpdate) AddMaxFeeSats(u int64) *UtxoSwapUpdate {
	usu.mutation.AddMaxFeeSats(u)
	return usu
}

// ClearMaxFeeSats clears the value of the "max_fee_sats" field.
func (usu *UtxoSwapUpdate) ClearMaxFeeSats() *UtxoSwapUpdate {
	usu.mutation.ClearMaxFeeSats()
	return usu
}

// SetSspSignature sets the "ssp_signature" field.
func (usu *UtxoSwapUpdate) SetSspSignature(b []byte) *UtxoSwapUpdate {
	usu.mutation.SetSspSignature(b)
	return usu
}

// ClearSspSignature clears the value of the "ssp_signature" field.
func (usu *UtxoSwapUpdate) ClearSspSignature() *UtxoSwapUpdate {
	usu.mutation.ClearSspSignature()
	return usu
}

// SetSspIdentityPublicKey sets the "ssp_identity_public_key" field.
func (usu *UtxoSwapUpdate) SetSspIdentityPublicKey(k keys.Public) *UtxoSwapUpdate {
	usu.mutation.SetSspIdentityPublicKey(k)
	return usu
}

// SetNillableSspIdentityPublicKey sets the "ssp_identity_public_key" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableSspIdentityPublicKey(k *keys.Public) *UtxoSwapUpdate {
	if k != nil {
		usu.SetSspIdentityPublicKey(*k)
	}
	return usu
}

// ClearSspIdentityPublicKey clears the value of the "ssp_identity_public_key" field.
func (usu *UtxoSwapUpdate) ClearSspIdentityPublicKey() *UtxoSwapUpdate {
	usu.mutation.ClearSspIdentityPublicKey()
	return usu
}

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

// ClearUserSignature clears the value of the "user_signature" field.
func (usu *UtxoSwapUpdate) ClearUserSignature() *UtxoSwapUpdate {
	usu.mutation.ClearUserSignature()
	return usu
}

// SetUserIdentityPublicKey sets the "user_identity_public_key" field.
func (usu *UtxoSwapUpdate) SetUserIdentityPublicKey(k keys.Public) *UtxoSwapUpdate {
	usu.mutation.SetUserIdentityPublicKey(k)
	return usu
}

// SetNillableUserIdentityPublicKey sets the "user_identity_public_key" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableUserIdentityPublicKey(k *keys.Public) *UtxoSwapUpdate {
	if k != nil {
		usu.SetUserIdentityPublicKey(*k)
	}
	return usu
}

// ClearUserIdentityPublicKey clears the value of the "user_identity_public_key" field.
func (usu *UtxoSwapUpdate) ClearUserIdentityPublicKey() *UtxoSwapUpdate {
	usu.mutation.ClearUserIdentityPublicKey()
	return usu
}

// SetCoordinatorIdentityPublicKey sets the "coordinator_identity_public_key" field.
func (usu *UtxoSwapUpdate) SetCoordinatorIdentityPublicKey(k keys.Public) *UtxoSwapUpdate {
	usu.mutation.SetCoordinatorIdentityPublicKey(k)
	return usu
}

// SetNillableCoordinatorIdentityPublicKey sets the "coordinator_identity_public_key" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableCoordinatorIdentityPublicKey(k *keys.Public) *UtxoSwapUpdate {
	if k != nil {
		usu.SetCoordinatorIdentityPublicKey(*k)
	}
	return usu
}

// SetRequestedTransferID sets the "requested_transfer_id" field.
func (usu *UtxoSwapUpdate) SetRequestedTransferID(u uuid.UUID) *UtxoSwapUpdate {
	usu.mutation.SetRequestedTransferID(u)
	return usu
}

// SetNillableRequestedTransferID sets the "requested_transfer_id" field if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableRequestedTransferID(u *uuid.UUID) *UtxoSwapUpdate {
	if u != nil {
		usu.SetRequestedTransferID(*u)
	}
	return usu
}

// ClearRequestedTransferID clears the value of the "requested_transfer_id" field.
func (usu *UtxoSwapUpdate) ClearRequestedTransferID() *UtxoSwapUpdate {
	usu.mutation.ClearRequestedTransferID()
	return usu
}

// SetSpendTxSigningResult sets the "spend_tx_signing_result" field.
func (usu *UtxoSwapUpdate) SetSpendTxSigningResult(b []byte) *UtxoSwapUpdate {
	usu.mutation.SetSpendTxSigningResult(b)
	return usu
}

// ClearSpendTxSigningResult clears the value of the "spend_tx_signing_result" field.
func (usu *UtxoSwapUpdate) ClearSpendTxSigningResult() *UtxoSwapUpdate {
	usu.mutation.ClearSpendTxSigningResult()
	return usu
}

// SetTransferID sets the "transfer" edge to the Transfer entity by ID.
func (usu *UtxoSwapUpdate) SetTransferID(id uuid.UUID) *UtxoSwapUpdate {
	usu.mutation.SetTransferID(id)
	return usu
}

// SetNillableTransferID sets the "transfer" edge to the Transfer entity by ID if the given value is not nil.
func (usu *UtxoSwapUpdate) SetNillableTransferID(id *uuid.UUID) *UtxoSwapUpdate {
	if id != nil {
		usu = usu.SetTransferID(*id)
	}
	return usu
}

// SetTransfer sets the "transfer" edge to the Transfer entity.
func (usu *UtxoSwapUpdate) SetTransfer(t *Transfer) *UtxoSwapUpdate {
	return usu.SetTransferID(t.ID)
}

// Mutation returns the UtxoSwapMutation object of the builder.
func (usu *UtxoSwapUpdate) Mutation() *UtxoSwapMutation {
	return usu.mutation
}

// ClearTransfer clears the "transfer" edge to the Transfer entity.
func (usu *UtxoSwapUpdate) ClearTransfer() *UtxoSwapUpdate {
	usu.mutation.ClearTransfer()
	return usu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (usu *UtxoSwapUpdate) Save(ctx context.Context) (int, error) {
	usu.defaults()
	return withHooks(ctx, usu.sqlSave, usu.mutation, usu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (usu *UtxoSwapUpdate) SaveX(ctx context.Context) int {
	affected, err := usu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

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

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

// defaults sets the default values of the builder before save.
func (usu *UtxoSwapUpdate) defaults() {
	if _, ok := usu.mutation.UpdateTime(); !ok {
		v := utxoswap.UpdateDefaultUpdateTime()
		usu.mutation.SetUpdateTime(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (usu *UtxoSwapUpdate) check() error {
	if v, ok := usu.mutation.Status(); ok {
		if err := utxoswap.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UtxoSwap.status": %w`, err)}
		}
	}
	if v, ok := usu.mutation.RequestType(); ok {
		if err := utxoswap.RequestTypeValidator(v); err != nil {
			return &ValidationError{Name: "request_type", err: fmt.Errorf(`ent: validator failed for field "UtxoSwap.request_type": %w`, err)}
		}
	}
	if usu.mutation.UtxoCleared() && len(usu.mutation.UtxoIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UtxoSwap.utxo"`)
	}
	return nil
}

func (usu *UtxoSwapUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := usu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(utxoswap.Table, utxoswap.Columns, sqlgraph.NewFieldSpec(utxoswap.FieldID, field.TypeUUID))
	if ps := usu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := usu.mutation.UpdateTime(); ok {
		_spec.SetField(utxoswap.FieldUpdateTime, field.TypeTime, value)
	}
	if value, ok := usu.mutation.Status(); ok {
		_spec.SetField(utxoswap.FieldStatus, field.TypeEnum, value)
	}
	if value, ok := usu.mutation.RequestType(); ok {
		_spec.SetField(utxoswap.FieldRequestType, field.TypeEnum, value)
	}
	if value, ok := usu.mutation.CreditAmountSats(); ok {
		_spec.SetField(utxoswap.FieldCreditAmountSats, field.TypeUint64, value)
	}
	if value, ok := usu.mutation.AddedCreditAmountSats(); ok {
		_spec.AddField(utxoswap.FieldCreditAmountSats, field.TypeUint64, value)
	}
	if usu.mutation.CreditAmountSatsCleared() {
		_spec.ClearField(utxoswap.FieldCreditAmountSats, field.TypeUint64)
	}
	if value, ok := usu.mutation.MaxFeeSats(); ok {
		_spec.SetField(utxoswap.FieldMaxFeeSats, field.TypeUint64, value)
	}
	if value, ok := usu.mutation.AddedMaxFeeSats(); ok {
		_spec.AddField(utxoswap.FieldMaxFeeSats, field.TypeUint64, value)
	}
	if usu.mutation.MaxFeeSatsCleared() {
		_spec.ClearField(utxoswap.FieldMaxFeeSats, field.TypeUint64)
	}
	if value, ok := usu.mutation.SspSignature(); ok {
		_spec.SetField(utxoswap.FieldSspSignature, field.TypeBytes, value)
	}
	if usu.mutation.SspSignatureCleared() {
		_spec.ClearField(utxoswap.FieldSspSignature, field.TypeBytes)
	}
	if value, ok := usu.mutation.SspIdentityPublicKey(); ok {
		_spec.SetField(utxoswap.FieldSspIdentityPublicKey, field.TypeBytes, value)
	}
	if usu.mutation.SspIdentityPublicKeyCleared() {
		_spec.ClearField(utxoswap.FieldSspIdentityPublicKey, field.TypeBytes)
	}
	if value, ok := usu.mutation.UserSignature(); ok {
		_spec.SetField(utxoswap.FieldUserSignature, field.TypeBytes, value)
	}
	if usu.mutation.UserSignatureCleared() {
		_spec.ClearField(utxoswap.FieldUserSignature, field.TypeBytes)
	}
	if value, ok := usu.mutation.UserIdentityPublicKey(); ok {
		_spec.SetField(utxoswap.FieldUserIdentityPublicKey, field.TypeBytes, value)
	}
	if usu.mutation.UserIdentityPublicKeyCleared() {
		_spec.ClearField(utxoswap.FieldUserIdentityPublicKey, field.TypeBytes)
	}
	if value, ok := usu.mutation.CoordinatorIdentityPublicKey(); ok {
		_spec.SetField(utxoswap.FieldCoordinatorIdentityPublicKey, field.TypeBytes, value)
	}
	if value, ok := usu.mutation.RequestedTransferID(); ok {
		_spec.SetField(utxoswap.FieldRequestedTransferID, field.TypeUUID, value)
	}
	if usu.mutation.RequestedTransferIDCleared() {
		_spec.ClearField(utxoswap.FieldRequestedTransferID, field.TypeUUID)
	}
	if value, ok := usu.mutation.SpendTxSigningResult(); ok {
		_spec.SetField(utxoswap.FieldSpendTxSigningResult, field.TypeBytes, value)
	}
	if usu.mutation.SpendTxSigningResultCleared() {
		_spec.ClearField(utxoswap.FieldSpendTxSigningResult, field.TypeBytes)
	}
	if usu.mutation.TransferCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   utxoswap.TransferTable,
			Columns: []string{utxoswap.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := usu.mutation.TransferIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   utxoswap.TransferTable,
			Columns: []string{utxoswap.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, usu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{utxoswap.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	usu.mutation.done = true
	return n, nil
}

// UtxoSwapUpdateOne is the builder for updating a single UtxoSwap entity.
type UtxoSwapUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UtxoSwapMutation
}

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

// SetStatus sets the "status" field.
func (usuo *UtxoSwapUpdateOne) SetStatus(sss schematype.UtxoSwapStatus) *UtxoSwapUpdateOne {
	usuo.mutation.SetStatus(sss)
	return usuo
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableStatus(sss *schematype.UtxoSwapStatus) *UtxoSwapUpdateOne {
	if sss != nil {
		usuo.SetStatus(*sss)
	}
	return usuo
}

// SetRequestType sets the "request_type" field.
func (usuo *UtxoSwapUpdateOne) SetRequestType(ssrt schematype.UtxoSwapRequestType) *UtxoSwapUpdateOne {
	usuo.mutation.SetRequestType(ssrt)
	return usuo
}

// SetNillableRequestType sets the "request_type" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableRequestType(ssrt *schematype.UtxoSwapRequestType) *UtxoSwapUpdateOne {
	if ssrt != nil {
		usuo.SetRequestType(*ssrt)
	}
	return usuo
}

// SetCreditAmountSats sets the "credit_amount_sats" field.
func (usuo *UtxoSwapUpdateOne) SetCreditAmountSats(u uint64) *UtxoSwapUpdateOne {
	usuo.mutation.ResetCreditAmountSats()
	usuo.mutation.SetCreditAmountSats(u)
	return usuo
}

// SetNillableCreditAmountSats sets the "credit_amount_sats" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableCreditAmountSats(u *uint64) *UtxoSwapUpdateOne {
	if u != nil {
		usuo.SetCreditAmountSats(*u)
	}
	return usuo
}

// AddCreditAmountSats adds u to the "credit_amount_sats" field.
func (usuo *UtxoSwapUpdateOne) AddCreditAmountSats(u int64) *UtxoSwapUpdateOne {
	usuo.mutation.AddCreditAmountSats(u)
	return usuo
}

// ClearCreditAmountSats clears the value of the "credit_amount_sats" field.
func (usuo *UtxoSwapUpdateOne) ClearCreditAmountSats() *UtxoSwapUpdateOne {
	usuo.mutation.ClearCreditAmountSats()
	return usuo
}

// SetMaxFeeSats sets the "max_fee_sats" field.
func (usuo *UtxoSwapUpdateOne) SetMaxFeeSats(u uint64) *UtxoSwapUpdateOne {
	usuo.mutation.ResetMaxFeeSats()
	usuo.mutation.SetMaxFeeSats(u)
	return usuo
}

// SetNillableMaxFeeSats sets the "max_fee_sats" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableMaxFeeSats(u *uint64) *UtxoSwapUpdateOne {
	if u != nil {
		usuo.SetMaxFeeSats(*u)
	}
	return usuo
}

// AddMaxFeeSats adds u to the "max_fee_sats" field.
func (usuo *UtxoSwapUpdateOne) AddMaxFeeSats(u int64) *UtxoSwapUpdateOne {
	usuo.mutation.AddMaxFeeSats(u)
	return usuo
}

// ClearMaxFeeSats clears the value of the "max_fee_sats" field.
func (usuo *UtxoSwapUpdateOne) ClearMaxFeeSats() *UtxoSwapUpdateOne {
	usuo.mutation.ClearMaxFeeSats()
	return usuo
}

// SetSspSignature sets the "ssp_signature" field.
func (usuo *UtxoSwapUpdateOne) SetSspSignature(b []byte) *UtxoSwapUpdateOne {
	usuo.mutation.SetSspSignature(b)
	return usuo
}

// ClearSspSignature clears the value of the "ssp_signature" field.
func (usuo *UtxoSwapUpdateOne) ClearSspSignature() *UtxoSwapUpdateOne {
	usuo.mutation.ClearSspSignature()
	return usuo
}

// SetSspIdentityPublicKey sets the "ssp_identity_public_key" field.
func (usuo *UtxoSwapUpdateOne) SetSspIdentityPublicKey(k keys.Public) *UtxoSwapUpdateOne {
	usuo.mutation.SetSspIdentityPublicKey(k)
	return usuo
}

// SetNillableSspIdentityPublicKey sets the "ssp_identity_public_key" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableSspIdentityPublicKey(k *keys.Public) *UtxoSwapUpdateOne {
	if k != nil {
		usuo.SetSspIdentityPublicKey(*k)
	}
	return usuo
}

// ClearSspIdentityPublicKey clears the value of the "ssp_identity_public_key" field.
func (usuo *UtxoSwapUpdateOne) ClearSspIdentityPublicKey() *UtxoSwapUpdateOne {
	usuo.mutation.ClearSspIdentityPublicKey()
	return usuo
}

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

// ClearUserSignature clears the value of the "user_signature" field.
func (usuo *UtxoSwapUpdateOne) ClearUserSignature() *UtxoSwapUpdateOne {
	usuo.mutation.ClearUserSignature()
	return usuo
}

// SetUserIdentityPublicKey sets the "user_identity_public_key" field.
func (usuo *UtxoSwapUpdateOne) SetUserIdentityPublicKey(k keys.Public) *UtxoSwapUpdateOne {
	usuo.mutation.SetUserIdentityPublicKey(k)
	return usuo
}

// SetNillableUserIdentityPublicKey sets the "user_identity_public_key" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableUserIdentityPublicKey(k *keys.Public) *UtxoSwapUpdateOne {
	if k != nil {
		usuo.SetUserIdentityPublicKey(*k)
	}
	return usuo
}

// ClearUserIdentityPublicKey clears the value of the "user_identity_public_key" field.
func (usuo *UtxoSwapUpdateOne) ClearUserIdentityPublicKey() *UtxoSwapUpdateOne {
	usuo.mutation.ClearUserIdentityPublicKey()
	return usuo
}

// SetCoordinatorIdentityPublicKey sets the "coordinator_identity_public_key" field.
func (usuo *UtxoSwapUpdateOne) SetCoordinatorIdentityPublicKey(k keys.Public) *UtxoSwapUpdateOne {
	usuo.mutation.SetCoordinatorIdentityPublicKey(k)
	return usuo
}

// SetNillableCoordinatorIdentityPublicKey sets the "coordinator_identity_public_key" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableCoordinatorIdentityPublicKey(k *keys.Public) *UtxoSwapUpdateOne {
	if k != nil {
		usuo.SetCoordinatorIdentityPublicKey(*k)
	}
	return usuo
}

// SetRequestedTransferID sets the "requested_transfer_id" field.
func (usuo *UtxoSwapUpdateOne) SetRequestedTransferID(u uuid.UUID) *UtxoSwapUpdateOne {
	usuo.mutation.SetRequestedTransferID(u)
	return usuo
}

// SetNillableRequestedTransferID sets the "requested_transfer_id" field if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableRequestedTransferID(u *uuid.UUID) *UtxoSwapUpdateOne {
	if u != nil {
		usuo.SetRequestedTransferID(*u)
	}
	return usuo
}

// ClearRequestedTransferID clears the value of the "requested_transfer_id" field.
func (usuo *UtxoSwapUpdateOne) ClearRequestedTransferID() *UtxoSwapUpdateOne {
	usuo.mutation.ClearRequestedTransferID()
	return usuo
}

// SetSpendTxSigningResult sets the "spend_tx_signing_result" field.
func (usuo *UtxoSwapUpdateOne) SetSpendTxSigningResult(b []byte) *UtxoSwapUpdateOne {
	usuo.mutation.SetSpendTxSigningResult(b)
	return usuo
}

// ClearSpendTxSigningResult clears the value of the "spend_tx_signing_result" field.
func (usuo *UtxoSwapUpdateOne) ClearSpendTxSigningResult() *UtxoSwapUpdateOne {
	usuo.mutation.ClearSpendTxSigningResult()
	return usuo
}

// SetTransferID sets the "transfer" edge to the Transfer entity by ID.
func (usuo *UtxoSwapUpdateOne) SetTransferID(id uuid.UUID) *UtxoSwapUpdateOne {
	usuo.mutation.SetTransferID(id)
	return usuo
}

// SetNillableTransferID sets the "transfer" edge to the Transfer entity by ID if the given value is not nil.
func (usuo *UtxoSwapUpdateOne) SetNillableTransferID(id *uuid.UUID) *UtxoSwapUpdateOne {
	if id != nil {
		usuo = usuo.SetTransferID(*id)
	}
	return usuo
}

// SetTransfer sets the "transfer" edge to the Transfer entity.
func (usuo *UtxoSwapUpdateOne) SetTransfer(t *Transfer) *UtxoSwapUpdateOne {
	return usuo.SetTransferID(t.ID)
}

// Mutation returns the UtxoSwapMutation object of the builder.
func (usuo *UtxoSwapUpdateOne) Mutation() *UtxoSwapMutation {
	return usuo.mutation
}

// ClearTransfer clears the "transfer" edge to the Transfer entity.
func (usuo *UtxoSwapUpdateOne) ClearTransfer() *UtxoSwapUpdateOne {
	usuo.mutation.ClearTransfer()
	return usuo
}

// Where appends a list predicates to the UtxoSwapUpdate builder.
func (usuo *UtxoSwapUpdateOne) Where(ps ...predicate.UtxoSwap) *UtxoSwapUpdateOne {
	usuo.mutation.Where(ps...)
	return usuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (usuo *UtxoSwapUpdateOne) Select(field string, fields ...string) *UtxoSwapUpdateOne {
	usuo.fields = append([]string{field}, fields...)
	return usuo
}

// Save executes the query and returns the updated UtxoSwap entity.
func (usuo *UtxoSwapUpdateOne) Save(ctx context.Context) (*UtxoSwap, error) {
	usuo.defaults()
	return withHooks(ctx, usuo.sqlSave, usuo.mutation, usuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (usuo *UtxoSwapUpdateOne) SaveX(ctx context.Context) *UtxoSwap {
	node, err := usuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (usuo *UtxoSwapUpdateOne) Exec(ctx context.Context) error {
	_, err := usuo.Save(ctx)
	return err
}

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

// defaults sets the default values of the builder before save.
func (usuo *UtxoSwapUpdateOne) defaults() {
	if _, ok := usuo.mutation.UpdateTime(); !ok {
		v := utxoswap.UpdateDefaultUpdateTime()
		usuo.mutation.SetUpdateTime(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (usuo *UtxoSwapUpdateOne) check() error {
	if v, ok := usuo.mutation.Status(); ok {
		if err := utxoswap.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UtxoSwap.status": %w`, err)}
		}
	}
	if v, ok := usuo.mutation.RequestType(); ok {
		if err := utxoswap.RequestTypeValidator(v); err != nil {
			return &ValidationError{Name: "request_type", err: fmt.Errorf(`ent: validator failed for field "UtxoSwap.request_type": %w`, err)}
		}
	}
	if usuo.mutation.UtxoCleared() && len(usuo.mutation.UtxoIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UtxoSwap.utxo"`)
	}
	return nil
}

func (usuo *UtxoSwapUpdateOne) sqlSave(ctx context.Context) (_node *UtxoSwap, err error) {
	if err := usuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(utxoswap.Table, utxoswap.Columns, sqlgraph.NewFieldSpec(utxoswap.FieldID, field.TypeUUID))
	id, ok := usuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UtxoSwap.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := usuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, utxoswap.FieldID)
		for _, f := range fields {
			if !utxoswap.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != utxoswap.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := usuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := usuo.mutation.UpdateTime(); ok {
		_spec.SetField(utxoswap.FieldUpdateTime, field.TypeTime, value)
	}
	if value, ok := usuo.mutation.Status(); ok {
		_spec.SetField(utxoswap.FieldStatus, field.TypeEnum, value)
	}
	if value, ok := usuo.mutation.RequestType(); ok {
		_spec.SetField(utxoswap.FieldRequestType, field.TypeEnum, value)
	}
	if value, ok := usuo.mutation.CreditAmountSats(); ok {
		_spec.SetField(utxoswap.FieldCreditAmountSats, field.TypeUint64, value)
	}
	if value, ok := usuo.mutation.AddedCreditAmountSats(); ok {
		_spec.AddField(utxoswap.FieldCreditAmountSats, field.TypeUint64, value)
	}
	if usuo.mutation.CreditAmountSatsCleared() {
		_spec.ClearField(utxoswap.FieldCreditAmountSats, field.TypeUint64)
	}
	if value, ok := usuo.mutation.MaxFeeSats(); ok {
		_spec.SetField(utxoswap.FieldMaxFeeSats, field.TypeUint64, value)
	}
	if value, ok := usuo.mutation.AddedMaxFeeSats(); ok {
		_spec.AddField(utxoswap.FieldMaxFeeSats, field.TypeUint64, value)
	}
	if usuo.mutation.MaxFeeSatsCleared() {
		_spec.ClearField(utxoswap.FieldMaxFeeSats, field.TypeUint64)
	}
	if value, ok := usuo.mutation.SspSignature(); ok {
		_spec.SetField(utxoswap.FieldSspSignature, field.TypeBytes, value)
	}
	if usuo.mutation.SspSignatureCleared() {
		_spec.ClearField(utxoswap.FieldSspSignature, field.TypeBytes)
	}
	if value, ok := usuo.mutation.SspIdentityPublicKey(); ok {
		_spec.SetField(utxoswap.FieldSspIdentityPublicKey, field.TypeBytes, value)
	}
	if usuo.mutation.SspIdentityPublicKeyCleared() {
		_spec.ClearField(utxoswap.FieldSspIdentityPublicKey, field.TypeBytes)
	}
	if value, ok := usuo.mutation.UserSignature(); ok {
		_spec.SetField(utxoswap.FieldUserSignature, field.TypeBytes, value)
	}
	if usuo.mutation.UserSignatureCleared() {
		_spec.ClearField(utxoswap.FieldUserSignature, field.TypeBytes)
	}
	if value, ok := usuo.mutation.UserIdentityPublicKey(); ok {
		_spec.SetField(utxoswap.FieldUserIdentityPublicKey, field.TypeBytes, value)
	}
	if usuo.mutation.UserIdentityPublicKeyCleared() {
		_spec.ClearField(utxoswap.FieldUserIdentityPublicKey, field.TypeBytes)
	}
	if value, ok := usuo.mutation.CoordinatorIdentityPublicKey(); ok {
		_spec.SetField(utxoswap.FieldCoordinatorIdentityPublicKey, field.TypeBytes, value)
	}
	if value, ok := usuo.mutation.RequestedTransferID(); ok {
		_spec.SetField(utxoswap.FieldRequestedTransferID, field.TypeUUID, value)
	}
	if usuo.mutation.RequestedTransferIDCleared() {
		_spec.ClearField(utxoswap.FieldRequestedTransferID, field.TypeUUID)
	}
	if value, ok := usuo.mutation.SpendTxSigningResult(); ok {
		_spec.SetField(utxoswap.FieldSpendTxSigningResult, field.TypeBytes, value)
	}
	if usuo.mutation.SpendTxSigningResultCleared() {
		_spec.ClearField(utxoswap.FieldSpendTxSigningResult, field.TypeBytes)
	}
	if usuo.mutation.TransferCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   utxoswap.TransferTable,
			Columns: []string{utxoswap.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := usuo.mutation.TransferIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   utxoswap.TransferTable,
			Columns: []string{utxoswap.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &UtxoSwap{config: usuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, usuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{utxoswap.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	usuo.mutation.done = true
	return _node, nil
}
