// 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/Wei-Shaw/sub2api/ent/idempotencyrecord"
)

// IdempotencyRecordCreate is the builder for creating a IdempotencyRecord entity.
type IdempotencyRecordCreate struct {
	config
	mutation *IdempotencyRecordMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (_c *IdempotencyRecordCreate) SetCreatedAt(v time.Time) *IdempotencyRecordCreate {
	_c.mutation.SetCreatedAt(v)
	return _c
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *IdempotencyRecordCreate) SetNillableCreatedAt(v *time.Time) *IdempotencyRecordCreate {
	if v != nil {
		_c.SetCreatedAt(*v)
	}
	return _c
}

// SetUpdatedAt sets the "updated_at" field.
func (_c *IdempotencyRecordCreate) SetUpdatedAt(v time.Time) *IdempotencyRecordCreate {
	_c.mutation.SetUpdatedAt(v)
	return _c
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *IdempotencyRecordCreate) SetNillableUpdatedAt(v *time.Time) *IdempotencyRecordCreate {
	if v != nil {
		_c.SetUpdatedAt(*v)
	}
	return _c
}

// SetScope sets the "scope" field.
func (_c *IdempotencyRecordCreate) SetScope(v string) *IdempotencyRecordCreate {
	_c.mutation.SetScope(v)
	return _c
}

// SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
func (_c *IdempotencyRecordCreate) SetIdempotencyKeyHash(v string) *IdempotencyRecordCreate {
	_c.mutation.SetIdempotencyKeyHash(v)
	return _c
}

// SetRequestFingerprint sets the "request_fingerprint" field.
func (_c *IdempotencyRecordCreate) SetRequestFingerprint(v string) *IdempotencyRecordCreate {
	_c.mutation.SetRequestFingerprint(v)
	return _c
}

// SetStatus sets the "status" field.
func (_c *IdempotencyRecordCreate) SetStatus(v string) *IdempotencyRecordCreate {
	_c.mutation.SetStatus(v)
	return _c
}

// SetResponseStatus sets the "response_status" field.
func (_c *IdempotencyRecordCreate) SetResponseStatus(v int) *IdempotencyRecordCreate {
	_c.mutation.SetResponseStatus(v)
	return _c
}

// SetNillableResponseStatus sets the "response_status" field if the given value is not nil.
func (_c *IdempotencyRecordCreate) SetNillableResponseStatus(v *int) *IdempotencyRecordCreate {
	if v != nil {
		_c.SetResponseStatus(*v)
	}
	return _c
}

// SetResponseBody sets the "response_body" field.
func (_c *IdempotencyRecordCreate) SetResponseBody(v string) *IdempotencyRecordCreate {
	_c.mutation.SetResponseBody(v)
	return _c
}

// SetNillableResponseBody sets the "response_body" field if the given value is not nil.
func (_c *IdempotencyRecordCreate) SetNillableResponseBody(v *string) *IdempotencyRecordCreate {
	if v != nil {
		_c.SetResponseBody(*v)
	}
	return _c
}

// SetErrorReason sets the "error_reason" field.
func (_c *IdempotencyRecordCreate) SetErrorReason(v string) *IdempotencyRecordCreate {
	_c.mutation.SetErrorReason(v)
	return _c
}

// SetNillableErrorReason sets the "error_reason" field if the given value is not nil.
func (_c *IdempotencyRecordCreate) SetNillableErrorReason(v *string) *IdempotencyRecordCreate {
	if v != nil {
		_c.SetErrorReason(*v)
	}
	return _c
}

// SetLockedUntil sets the "locked_until" field.
func (_c *IdempotencyRecordCreate) SetLockedUntil(v time.Time) *IdempotencyRecordCreate {
	_c.mutation.SetLockedUntil(v)
	return _c
}

// SetNillableLockedUntil sets the "locked_until" field if the given value is not nil.
func (_c *IdempotencyRecordCreate) SetNillableLockedUntil(v *time.Time) *IdempotencyRecordCreate {
	if v != nil {
		_c.SetLockedUntil(*v)
	}
	return _c
}

// SetExpiresAt sets the "expires_at" field.
func (_c *IdempotencyRecordCreate) SetExpiresAt(v time.Time) *IdempotencyRecordCreate {
	_c.mutation.SetExpiresAt(v)
	return _c
}

// Mutation returns the IdempotencyRecordMutation object of the builder.
func (_c *IdempotencyRecordCreate) Mutation() *IdempotencyRecordMutation {
	return _c.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (_c *IdempotencyRecordCreate) defaults() {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		v := idempotencyrecord.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		v := idempotencyrecord.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_c *IdempotencyRecordCreate) check() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "IdempotencyRecord.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "IdempotencyRecord.updated_at"`)}
	}
	if _, ok := _c.mutation.Scope(); !ok {
		return &ValidationError{Name: "scope", err: errors.New(`ent: missing required field "IdempotencyRecord.scope"`)}
	}
	if v, ok := _c.mutation.Scope(); ok {
		if err := idempotencyrecord.ScopeValidator(v); err != nil {
			return &ValidationError{Name: "scope", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.scope": %w`, err)}
		}
	}
	if _, ok := _c.mutation.IdempotencyKeyHash(); !ok {
		return &ValidationError{Name: "idempotency_key_hash", err: errors.New(`ent: missing required field "IdempotencyRecord.idempotency_key_hash"`)}
	}
	if v, ok := _c.mutation.IdempotencyKeyHash(); ok {
		if err := idempotencyrecord.IdempotencyKeyHashValidator(v); err != nil {
			return &ValidationError{Name: "idempotency_key_hash", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.idempotency_key_hash": %w`, err)}
		}
	}
	if _, ok := _c.mutation.RequestFingerprint(); !ok {
		return &ValidationError{Name: "request_fingerprint", err: errors.New(`ent: missing required field "IdempotencyRecord.request_fingerprint"`)}
	}
	if v, ok := _c.mutation.RequestFingerprint(); ok {
		if err := idempotencyrecord.RequestFingerprintValidator(v); err != nil {
			return &ValidationError{Name: "request_fingerprint", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.request_fingerprint": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Status(); !ok {
		return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "IdempotencyRecord.status"`)}
	}
	if v, ok := _c.mutation.Status(); ok {
		if err := idempotencyrecord.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.status": %w`, err)}
		}
	}
	if v, ok := _c.mutation.ErrorReason(); ok {
		if err := idempotencyrecord.ErrorReasonValidator(v); err != nil {
			return &ValidationError{Name: "error_reason", err: fmt.Errorf(`ent: validator failed for field "IdempotencyRecord.error_reason": %w`, err)}
		}
	}
	if _, ok := _c.mutation.ExpiresAt(); !ok {
		return &ValidationError{Name: "expires_at", err: errors.New(`ent: missing required field "IdempotencyRecord.expires_at"`)}
	}
	return nil
}

func (_c *IdempotencyRecordCreate) sqlSave(ctx context.Context) (*IdempotencyRecord, error) {
	if err := _c.check(); err != nil {
		return nil, err
	}
	_node, _spec := _c.createSpec()
	if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	id := _spec.ID.Value.(int64)
	_node.ID = int64(id)
	_c.mutation.id = &_node.ID
	_c.mutation.done = true
	return _node, nil
}

func (_c *IdempotencyRecordCreate) createSpec() (*IdempotencyRecord, *sqlgraph.CreateSpec) {
	var (
		_node = &IdempotencyRecord{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(idempotencyrecord.Table, sqlgraph.NewFieldSpec(idempotencyrecord.FieldID, field.TypeInt64))
	)
	_spec.OnConflict = _c.conflict
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(idempotencyrecord.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(idempotencyrecord.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := _c.mutation.Scope(); ok {
		_spec.SetField(idempotencyrecord.FieldScope, field.TypeString, value)
		_node.Scope = value
	}
	if value, ok := _c.mutation.IdempotencyKeyHash(); ok {
		_spec.SetField(idempotencyrecord.FieldIdempotencyKeyHash, field.TypeString, value)
		_node.IdempotencyKeyHash = value
	}
	if value, ok := _c.mutation.RequestFingerprint(); ok {
		_spec.SetField(idempotencyrecord.FieldRequestFingerprint, field.TypeString, value)
		_node.RequestFingerprint = value
	}
	if value, ok := _c.mutation.Status(); ok {
		_spec.SetField(idempotencyrecord.FieldStatus, field.TypeString, value)
		_node.Status = value
	}
	if value, ok := _c.mutation.ResponseStatus(); ok {
		_spec.SetField(idempotencyrecord.FieldResponseStatus, field.TypeInt, value)
		_node.ResponseStatus = &value
	}
	if value, ok := _c.mutation.ResponseBody(); ok {
		_spec.SetField(idempotencyrecord.FieldResponseBody, field.TypeString, value)
		_node.ResponseBody = &value
	}
	if value, ok := _c.mutation.ErrorReason(); ok {
		_spec.SetField(idempotencyrecord.FieldErrorReason, field.TypeString, value)
		_node.ErrorReason = &value
	}
	if value, ok := _c.mutation.LockedUntil(); ok {
		_spec.SetField(idempotencyrecord.FieldLockedUntil, field.TypeTime, value)
		_node.LockedUntil = &value
	}
	if value, ok := _c.mutation.ExpiresAt(); ok {
		_spec.SetField(idempotencyrecord.FieldExpiresAt, field.TypeTime, value)
		_node.ExpiresAt = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.IdempotencyRecord.Create().
//		SetCreatedAt(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.IdempotencyRecordUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *IdempotencyRecordCreate) OnConflict(opts ...sql.ConflictOption) *IdempotencyRecordUpsertOne {
	_c.conflict = opts
	return &IdempotencyRecordUpsertOne{
		create: _c,
	}
}

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

type (
	// IdempotencyRecordUpsertOne is the builder for "upsert"-ing
	//  one IdempotencyRecord node.
	IdempotencyRecordUpsertOne struct {
		create *IdempotencyRecordCreate
	}

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

// SetUpdatedAt sets the "updated_at" field.
func (u *IdempotencyRecordUpsert) SetUpdatedAt(v time.Time) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldUpdatedAt, v)
	return u
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateUpdatedAt() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldUpdatedAt)
	return u
}

// SetScope sets the "scope" field.
func (u *IdempotencyRecordUpsert) SetScope(v string) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldScope, v)
	return u
}

// UpdateScope sets the "scope" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateScope() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldScope)
	return u
}

// SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
func (u *IdempotencyRecordUpsert) SetIdempotencyKeyHash(v string) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldIdempotencyKeyHash, v)
	return u
}

// UpdateIdempotencyKeyHash sets the "idempotency_key_hash" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateIdempotencyKeyHash() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldIdempotencyKeyHash)
	return u
}

// SetRequestFingerprint sets the "request_fingerprint" field.
func (u *IdempotencyRecordUpsert) SetRequestFingerprint(v string) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldRequestFingerprint, v)
	return u
}

// UpdateRequestFingerprint sets the "request_fingerprint" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateRequestFingerprint() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldRequestFingerprint)
	return u
}

// SetStatus sets the "status" field.
func (u *IdempotencyRecordUpsert) SetStatus(v string) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldStatus, v)
	return u
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateStatus() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldStatus)
	return u
}

// SetResponseStatus sets the "response_status" field.
func (u *IdempotencyRecordUpsert) SetResponseStatus(v int) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldResponseStatus, v)
	return u
}

// UpdateResponseStatus sets the "response_status" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateResponseStatus() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldResponseStatus)
	return u
}

// AddResponseStatus adds v to the "response_status" field.
func (u *IdempotencyRecordUpsert) AddResponseStatus(v int) *IdempotencyRecordUpsert {
	u.Add(idempotencyrecord.FieldResponseStatus, v)
	return u
}

// ClearResponseStatus clears the value of the "response_status" field.
func (u *IdempotencyRecordUpsert) ClearResponseStatus() *IdempotencyRecordUpsert {
	u.SetNull(idempotencyrecord.FieldResponseStatus)
	return u
}

// SetResponseBody sets the "response_body" field.
func (u *IdempotencyRecordUpsert) SetResponseBody(v string) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldResponseBody, v)
	return u
}

// UpdateResponseBody sets the "response_body" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateResponseBody() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldResponseBody)
	return u
}

// ClearResponseBody clears the value of the "response_body" field.
func (u *IdempotencyRecordUpsert) ClearResponseBody() *IdempotencyRecordUpsert {
	u.SetNull(idempotencyrecord.FieldResponseBody)
	return u
}

// SetErrorReason sets the "error_reason" field.
func (u *IdempotencyRecordUpsert) SetErrorReason(v string) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldErrorReason, v)
	return u
}

// UpdateErrorReason sets the "error_reason" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateErrorReason() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldErrorReason)
	return u
}

// ClearErrorReason clears the value of the "error_reason" field.
func (u *IdempotencyRecordUpsert) ClearErrorReason() *IdempotencyRecordUpsert {
	u.SetNull(idempotencyrecord.FieldErrorReason)
	return u
}

// SetLockedUntil sets the "locked_until" field.
func (u *IdempotencyRecordUpsert) SetLockedUntil(v time.Time) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldLockedUntil, v)
	return u
}

// UpdateLockedUntil sets the "locked_until" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateLockedUntil() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldLockedUntil)
	return u
}

// ClearLockedUntil clears the value of the "locked_until" field.
func (u *IdempotencyRecordUpsert) ClearLockedUntil() *IdempotencyRecordUpsert {
	u.SetNull(idempotencyrecord.FieldLockedUntil)
	return u
}

// SetExpiresAt sets the "expires_at" field.
func (u *IdempotencyRecordUpsert) SetExpiresAt(v time.Time) *IdempotencyRecordUpsert {
	u.Set(idempotencyrecord.FieldExpiresAt, v)
	return u
}

// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *IdempotencyRecordUpsert) UpdateExpiresAt() *IdempotencyRecordUpsert {
	u.SetExcluded(idempotencyrecord.FieldExpiresAt)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
//	client.IdempotencyRecord.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *IdempotencyRecordUpsertOne) UpdateNewValues() *IdempotencyRecordUpsertOne {
	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.CreatedAt(); exists {
			s.SetIgnore(idempotencyrecord.FieldCreatedAt)
		}
	}))
	return u
}

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

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

// SetUpdatedAt sets the "updated_at" field.
func (u *IdempotencyRecordUpsertOne) SetUpdatedAt(v time.Time) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateUpdatedAt() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetScope sets the "scope" field.
func (u *IdempotencyRecordUpsertOne) SetScope(v string) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetScope(v)
	})
}

// UpdateScope sets the "scope" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateScope() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateScope()
	})
}

// SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
func (u *IdempotencyRecordUpsertOne) SetIdempotencyKeyHash(v string) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetIdempotencyKeyHash(v)
	})
}

// UpdateIdempotencyKeyHash sets the "idempotency_key_hash" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateIdempotencyKeyHash() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateIdempotencyKeyHash()
	})
}

// SetRequestFingerprint sets the "request_fingerprint" field.
func (u *IdempotencyRecordUpsertOne) SetRequestFingerprint(v string) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetRequestFingerprint(v)
	})
}

// UpdateRequestFingerprint sets the "request_fingerprint" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateRequestFingerprint() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateRequestFingerprint()
	})
}

// SetStatus sets the "status" field.
func (u *IdempotencyRecordUpsertOne) SetStatus(v string) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateStatus() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateStatus()
	})
}

// SetResponseStatus sets the "response_status" field.
func (u *IdempotencyRecordUpsertOne) SetResponseStatus(v int) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetResponseStatus(v)
	})
}

// AddResponseStatus adds v to the "response_status" field.
func (u *IdempotencyRecordUpsertOne) AddResponseStatus(v int) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.AddResponseStatus(v)
	})
}

// UpdateResponseStatus sets the "response_status" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateResponseStatus() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateResponseStatus()
	})
}

// ClearResponseStatus clears the value of the "response_status" field.
func (u *IdempotencyRecordUpsertOne) ClearResponseStatus() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearResponseStatus()
	})
}

// SetResponseBody sets the "response_body" field.
func (u *IdempotencyRecordUpsertOne) SetResponseBody(v string) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetResponseBody(v)
	})
}

// UpdateResponseBody sets the "response_body" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateResponseBody() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateResponseBody()
	})
}

// ClearResponseBody clears the value of the "response_body" field.
func (u *IdempotencyRecordUpsertOne) ClearResponseBody() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearResponseBody()
	})
}

// SetErrorReason sets the "error_reason" field.
func (u *IdempotencyRecordUpsertOne) SetErrorReason(v string) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetErrorReason(v)
	})
}

// UpdateErrorReason sets the "error_reason" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateErrorReason() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateErrorReason()
	})
}

// ClearErrorReason clears the value of the "error_reason" field.
func (u *IdempotencyRecordUpsertOne) ClearErrorReason() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearErrorReason()
	})
}

// SetLockedUntil sets the "locked_until" field.
func (u *IdempotencyRecordUpsertOne) SetLockedUntil(v time.Time) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetLockedUntil(v)
	})
}

// UpdateLockedUntil sets the "locked_until" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateLockedUntil() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateLockedUntil()
	})
}

// ClearLockedUntil clears the value of the "locked_until" field.
func (u *IdempotencyRecordUpsertOne) ClearLockedUntil() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearLockedUntil()
	})
}

// SetExpiresAt sets the "expires_at" field.
func (u *IdempotencyRecordUpsertOne) SetExpiresAt(v time.Time) *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetExpiresAt(v)
	})
}

// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertOne) UpdateExpiresAt() *IdempotencyRecordUpsertOne {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateExpiresAt()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *IdempotencyRecordUpsertOne) 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 *IdempotencyRecordUpsertOne) ID(ctx context.Context) (id int64, err error) {
	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 *IdempotencyRecordUpsertOne) IDX(ctx context.Context) int64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.IdempotencyRecord.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.IdempotencyRecordUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *IdempotencyRecordCreateBulk) OnConflict(opts ...sql.ConflictOption) *IdempotencyRecordUpsertBulk {
	_c.conflict = opts
	return &IdempotencyRecordUpsertBulk{
		create: _c,
	}
}

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

// IdempotencyRecordUpsertBulk is the builder for "upsert"-ing
// a bulk of IdempotencyRecord nodes.
type IdempotencyRecordUpsertBulk struct {
	create *IdempotencyRecordCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.IdempotencyRecord.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *IdempotencyRecordUpsertBulk) UpdateNewValues() *IdempotencyRecordUpsertBulk {
	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.CreatedAt(); exists {
				s.SetIgnore(idempotencyrecord.FieldCreatedAt)
			}
		}
	}))
	return u
}

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

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

// SetUpdatedAt sets the "updated_at" field.
func (u *IdempotencyRecordUpsertBulk) SetUpdatedAt(v time.Time) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateUpdatedAt() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetScope sets the "scope" field.
func (u *IdempotencyRecordUpsertBulk) SetScope(v string) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetScope(v)
	})
}

// UpdateScope sets the "scope" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateScope() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateScope()
	})
}

// SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
func (u *IdempotencyRecordUpsertBulk) SetIdempotencyKeyHash(v string) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetIdempotencyKeyHash(v)
	})
}

// UpdateIdempotencyKeyHash sets the "idempotency_key_hash" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateIdempotencyKeyHash() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateIdempotencyKeyHash()
	})
}

// SetRequestFingerprint sets the "request_fingerprint" field.
func (u *IdempotencyRecordUpsertBulk) SetRequestFingerprint(v string) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetRequestFingerprint(v)
	})
}

// UpdateRequestFingerprint sets the "request_fingerprint" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateRequestFingerprint() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateRequestFingerprint()
	})
}

// SetStatus sets the "status" field.
func (u *IdempotencyRecordUpsertBulk) SetStatus(v string) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateStatus() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateStatus()
	})
}

// SetResponseStatus sets the "response_status" field.
func (u *IdempotencyRecordUpsertBulk) SetResponseStatus(v int) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetResponseStatus(v)
	})
}

// AddResponseStatus adds v to the "response_status" field.
func (u *IdempotencyRecordUpsertBulk) AddResponseStatus(v int) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.AddResponseStatus(v)
	})
}

// UpdateResponseStatus sets the "response_status" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateResponseStatus() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateResponseStatus()
	})
}

// ClearResponseStatus clears the value of the "response_status" field.
func (u *IdempotencyRecordUpsertBulk) ClearResponseStatus() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearResponseStatus()
	})
}

// SetResponseBody sets the "response_body" field.
func (u *IdempotencyRecordUpsertBulk) SetResponseBody(v string) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetResponseBody(v)
	})
}

// UpdateResponseBody sets the "response_body" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateResponseBody() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateResponseBody()
	})
}

// ClearResponseBody clears the value of the "response_body" field.
func (u *IdempotencyRecordUpsertBulk) ClearResponseBody() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearResponseBody()
	})
}

// SetErrorReason sets the "error_reason" field.
func (u *IdempotencyRecordUpsertBulk) SetErrorReason(v string) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetErrorReason(v)
	})
}

// UpdateErrorReason sets the "error_reason" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateErrorReason() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateErrorReason()
	})
}

// ClearErrorReason clears the value of the "error_reason" field.
func (u *IdempotencyRecordUpsertBulk) ClearErrorReason() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearErrorReason()
	})
}

// SetLockedUntil sets the "locked_until" field.
func (u *IdempotencyRecordUpsertBulk) SetLockedUntil(v time.Time) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetLockedUntil(v)
	})
}

// UpdateLockedUntil sets the "locked_until" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateLockedUntil() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateLockedUntil()
	})
}

// ClearLockedUntil clears the value of the "locked_until" field.
func (u *IdempotencyRecordUpsertBulk) ClearLockedUntil() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.ClearLockedUntil()
	})
}

// SetExpiresAt sets the "expires_at" field.
func (u *IdempotencyRecordUpsertBulk) SetExpiresAt(v time.Time) *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.SetExpiresAt(v)
	})
}

// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *IdempotencyRecordUpsertBulk) UpdateExpiresAt() *IdempotencyRecordUpsertBulk {
	return u.Update(func(s *IdempotencyRecordUpsert) {
		s.UpdateExpiresAt()
	})
}

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

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