// 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/account"
	"github.com/Wei-Shaw/sub2api/ent/group"
)

// AccountCreate is the builder for creating a Account entity.
type AccountCreate struct {
	config
	mutation *AccountMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (_c *AccountCreate) SetDeletedAt(v time.Time) *AccountCreate {
	_c.mutation.SetDeletedAt(v)
	return _c
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_c *AccountCreate) SetNillableDeletedAt(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetDeletedAt(*v)
	}
	return _c
}

// SetName sets the "name" field.
func (_c *AccountCreate) SetName(v string) *AccountCreate {
	_c.mutation.SetName(v)
	return _c
}

// SetPlatform sets the "platform" field.
func (_c *AccountCreate) SetPlatform(v string) *AccountCreate {
	_c.mutation.SetPlatform(v)
	return _c
}

// SetType sets the "type" field.
func (_c *AccountCreate) SetType(v string) *AccountCreate {
	_c.mutation.SetType(v)
	return _c
}

// SetCredentials sets the "credentials" field.
func (_c *AccountCreate) SetCredentials(v map[string]interface{}) *AccountCreate {
	_c.mutation.SetCredentials(v)
	return _c
}

// SetExtra sets the "extra" field.
func (_c *AccountCreate) SetExtra(v map[string]interface{}) *AccountCreate {
	_c.mutation.SetExtra(v)
	return _c
}

// SetProxyID sets the "proxy_id" field.
func (_c *AccountCreate) SetProxyID(v int64) *AccountCreate {
	_c.mutation.SetProxyID(v)
	return _c
}

// SetNillableProxyID sets the "proxy_id" field if the given value is not nil.
func (_c *AccountCreate) SetNillableProxyID(v *int64) *AccountCreate {
	if v != nil {
		_c.SetProxyID(*v)
	}
	return _c
}

// SetConcurrency sets the "concurrency" field.
func (_c *AccountCreate) SetConcurrency(v int) *AccountCreate {
	_c.mutation.SetConcurrency(v)
	return _c
}

// SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
func (_c *AccountCreate) SetNillableConcurrency(v *int) *AccountCreate {
	if v != nil {
		_c.SetConcurrency(*v)
	}
	return _c
}

// SetPriority sets the "priority" field.
func (_c *AccountCreate) SetPriority(v int) *AccountCreate {
	_c.mutation.SetPriority(v)
	return _c
}

// SetNillablePriority sets the "priority" field if the given value is not nil.
func (_c *AccountCreate) SetNillablePriority(v *int) *AccountCreate {
	if v != nil {
		_c.SetPriority(*v)
	}
	return _c
}

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

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *AccountCreate) SetNillableStatus(v *string) *AccountCreate {
	if v != nil {
		_c.SetStatus(*v)
	}
	return _c
}

// SetErrorMessage sets the "error_message" field.
func (_c *AccountCreate) SetErrorMessage(v string) *AccountCreate {
	_c.mutation.SetErrorMessage(v)
	return _c
}

// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func (_c *AccountCreate) SetNillableErrorMessage(v *string) *AccountCreate {
	if v != nil {
		_c.SetErrorMessage(*v)
	}
	return _c
}

// SetLastUsedAt sets the "last_used_at" field.
func (_c *AccountCreate) SetLastUsedAt(v time.Time) *AccountCreate {
	_c.mutation.SetLastUsedAt(v)
	return _c
}

// SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
func (_c *AccountCreate) SetNillableLastUsedAt(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetLastUsedAt(*v)
	}
	return _c
}

// SetSchedulable sets the "schedulable" field.
func (_c *AccountCreate) SetSchedulable(v bool) *AccountCreate {
	_c.mutation.SetSchedulable(v)
	return _c
}

// SetNillableSchedulable sets the "schedulable" field if the given value is not nil.
func (_c *AccountCreate) SetNillableSchedulable(v *bool) *AccountCreate {
	if v != nil {
		_c.SetSchedulable(*v)
	}
	return _c
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (_c *AccountCreate) SetRateLimitedAt(v time.Time) *AccountCreate {
	_c.mutation.SetRateLimitedAt(v)
	return _c
}

// SetNillableRateLimitedAt sets the "rate_limited_at" field if the given value is not nil.
func (_c *AccountCreate) SetNillableRateLimitedAt(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetRateLimitedAt(*v)
	}
	return _c
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (_c *AccountCreate) SetRateLimitResetAt(v time.Time) *AccountCreate {
	_c.mutation.SetRateLimitResetAt(v)
	return _c
}

// SetNillableRateLimitResetAt sets the "rate_limit_reset_at" field if the given value is not nil.
func (_c *AccountCreate) SetNillableRateLimitResetAt(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetRateLimitResetAt(*v)
	}
	return _c
}

// SetOverloadUntil sets the "overload_until" field.
func (_c *AccountCreate) SetOverloadUntil(v time.Time) *AccountCreate {
	_c.mutation.SetOverloadUntil(v)
	return _c
}

// SetNillableOverloadUntil sets the "overload_until" field if the given value is not nil.
func (_c *AccountCreate) SetNillableOverloadUntil(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetOverloadUntil(*v)
	}
	return _c
}

// SetSessionWindowStart sets the "session_window_start" field.
func (_c *AccountCreate) SetSessionWindowStart(v time.Time) *AccountCreate {
	_c.mutation.SetSessionWindowStart(v)
	return _c
}

// SetNillableSessionWindowStart sets the "session_window_start" field if the given value is not nil.
func (_c *AccountCreate) SetNillableSessionWindowStart(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetSessionWindowStart(*v)
	}
	return _c
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (_c *AccountCreate) SetSessionWindowEnd(v time.Time) *AccountCreate {
	_c.mutation.SetSessionWindowEnd(v)
	return _c
}

// SetNillableSessionWindowEnd sets the "session_window_end" field if the given value is not nil.
func (_c *AccountCreate) SetNillableSessionWindowEnd(v *time.Time) *AccountCreate {
	if v != nil {
		_c.SetSessionWindowEnd(*v)
	}
	return _c
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (_c *AccountCreate) SetSessionWindowStatus(v string) *AccountCreate {
	_c.mutation.SetSessionWindowStatus(v)
	return _c
}

// SetNillableSessionWindowStatus sets the "session_window_status" field if the given value is not nil.
func (_c *AccountCreate) SetNillableSessionWindowStatus(v *string) *AccountCreate {
	if v != nil {
		_c.SetSessionWindowStatus(*v)
	}
	return _c
}

// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (_c *AccountCreate) AddGroupIDs(ids ...int64) *AccountCreate {
	_c.mutation.AddGroupIDs(ids...)
	return _c
}

// AddGroups adds the "groups" edges to the Group entity.
func (_c *AccountCreate) AddGroups(v ...*Group) *AccountCreate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _c.AddGroupIDs(ids...)
}

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

// Save creates the Account in the database.
func (_c *AccountCreate) Save(ctx context.Context) (*Account, error) {
	if err := _c.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}

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

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *AccountCreate) 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 *AccountCreate) defaults() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		if account.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized account.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := account.DefaultCreatedAt()
		_c.mutation.SetCreatedAt(v)
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		if account.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized account.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := account.DefaultUpdatedAt()
		_c.mutation.SetUpdatedAt(v)
	}
	if _, ok := _c.mutation.Credentials(); !ok {
		if account.DefaultCredentials == nil {
			return fmt.Errorf("ent: uninitialized account.DefaultCredentials (forgotten import ent/runtime?)")
		}
		v := account.DefaultCredentials()
		_c.mutation.SetCredentials(v)
	}
	if _, ok := _c.mutation.Extra(); !ok {
		if account.DefaultExtra == nil {
			return fmt.Errorf("ent: uninitialized account.DefaultExtra (forgotten import ent/runtime?)")
		}
		v := account.DefaultExtra()
		_c.mutation.SetExtra(v)
	}
	if _, ok := _c.mutation.Concurrency(); !ok {
		v := account.DefaultConcurrency
		_c.mutation.SetConcurrency(v)
	}
	if _, ok := _c.mutation.Priority(); !ok {
		v := account.DefaultPriority
		_c.mutation.SetPriority(v)
	}
	if _, ok := _c.mutation.Status(); !ok {
		v := account.DefaultStatus
		_c.mutation.SetStatus(v)
	}
	if _, ok := _c.mutation.Schedulable(); !ok {
		v := account.DefaultSchedulable
		_c.mutation.SetSchedulable(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (_c *AccountCreate) check() error {
	if _, ok := _c.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Account.created_at"`)}
	}
	if _, ok := _c.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Account.updated_at"`)}
	}
	if _, ok := _c.mutation.Name(); !ok {
		return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Account.name"`)}
	}
	if v, ok := _c.mutation.Name(); ok {
		if err := account.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Account.name": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Platform(); !ok {
		return &ValidationError{Name: "platform", err: errors.New(`ent: missing required field "Account.platform"`)}
	}
	if v, ok := _c.mutation.Platform(); ok {
		if err := account.PlatformValidator(v); err != nil {
			return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Account.platform": %w`, err)}
		}
	}
	if _, ok := _c.mutation.GetType(); !ok {
		return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Account.type"`)}
	}
	if v, ok := _c.mutation.GetType(); ok {
		if err := account.TypeValidator(v); err != nil {
			return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Account.type": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Credentials(); !ok {
		return &ValidationError{Name: "credentials", err: errors.New(`ent: missing required field "Account.credentials"`)}
	}
	if _, ok := _c.mutation.Extra(); !ok {
		return &ValidationError{Name: "extra", err: errors.New(`ent: missing required field "Account.extra"`)}
	}
	if _, ok := _c.mutation.Concurrency(); !ok {
		return &ValidationError{Name: "concurrency", err: errors.New(`ent: missing required field "Account.concurrency"`)}
	}
	if _, ok := _c.mutation.Priority(); !ok {
		return &ValidationError{Name: "priority", err: errors.New(`ent: missing required field "Account.priority"`)}
	}
	if _, ok := _c.mutation.Status(); !ok {
		return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Account.status"`)}
	}
	if v, ok := _c.mutation.Status(); ok {
		if err := account.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Account.status": %w`, err)}
		}
	}
	if _, ok := _c.mutation.Schedulable(); !ok {
		return &ValidationError{Name: "schedulable", err: errors.New(`ent: missing required field "Account.schedulable"`)}
	}
	if v, ok := _c.mutation.SessionWindowStatus(); ok {
		if err := account.SessionWindowStatusValidator(v); err != nil {
			return &ValidationError{Name: "session_window_status", err: fmt.Errorf(`ent: validator failed for field "Account.session_window_status": %w`, err)}
		}
	}
	return nil
}

func (_c *AccountCreate) sqlSave(ctx context.Context) (*Account, 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 *AccountCreate) createSpec() (*Account, *sqlgraph.CreateSpec) {
	var (
		_node = &Account{config: _c.config}
		_spec = sqlgraph.NewCreateSpec(account.Table, sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64))
	)
	_spec.OnConflict = _c.conflict
	if value, ok := _c.mutation.CreatedAt(); ok {
		_spec.SetField(account.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := _c.mutation.UpdatedAt(); ok {
		_spec.SetField(account.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := _c.mutation.DeletedAt(); ok {
		_spec.SetField(account.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = &value
	}
	if value, ok := _c.mutation.Name(); ok {
		_spec.SetField(account.FieldName, field.TypeString, value)
		_node.Name = value
	}
	if value, ok := _c.mutation.Platform(); ok {
		_spec.SetField(account.FieldPlatform, field.TypeString, value)
		_node.Platform = value
	}
	if value, ok := _c.mutation.GetType(); ok {
		_spec.SetField(account.FieldType, field.TypeString, value)
		_node.Type = value
	}
	if value, ok := _c.mutation.Credentials(); ok {
		_spec.SetField(account.FieldCredentials, field.TypeJSON, value)
		_node.Credentials = value
	}
	if value, ok := _c.mutation.Extra(); ok {
		_spec.SetField(account.FieldExtra, field.TypeJSON, value)
		_node.Extra = value
	}
	if value, ok := _c.mutation.ProxyID(); ok {
		_spec.SetField(account.FieldProxyID, field.TypeInt64, value)
		_node.ProxyID = &value
	}
	if value, ok := _c.mutation.Concurrency(); ok {
		_spec.SetField(account.FieldConcurrency, field.TypeInt, value)
		_node.Concurrency = value
	}
	if value, ok := _c.mutation.Priority(); ok {
		_spec.SetField(account.FieldPriority, field.TypeInt, value)
		_node.Priority = value
	}
	if value, ok := _c.mutation.Status(); ok {
		_spec.SetField(account.FieldStatus, field.TypeString, value)
		_node.Status = value
	}
	if value, ok := _c.mutation.ErrorMessage(); ok {
		_spec.SetField(account.FieldErrorMessage, field.TypeString, value)
		_node.ErrorMessage = &value
	}
	if value, ok := _c.mutation.LastUsedAt(); ok {
		_spec.SetField(account.FieldLastUsedAt, field.TypeTime, value)
		_node.LastUsedAt = &value
	}
	if value, ok := _c.mutation.Schedulable(); ok {
		_spec.SetField(account.FieldSchedulable, field.TypeBool, value)
		_node.Schedulable = value
	}
	if value, ok := _c.mutation.RateLimitedAt(); ok {
		_spec.SetField(account.FieldRateLimitedAt, field.TypeTime, value)
		_node.RateLimitedAt = &value
	}
	if value, ok := _c.mutation.RateLimitResetAt(); ok {
		_spec.SetField(account.FieldRateLimitResetAt, field.TypeTime, value)
		_node.RateLimitResetAt = &value
	}
	if value, ok := _c.mutation.OverloadUntil(); ok {
		_spec.SetField(account.FieldOverloadUntil, field.TypeTime, value)
		_node.OverloadUntil = &value
	}
	if value, ok := _c.mutation.SessionWindowStart(); ok {
		_spec.SetField(account.FieldSessionWindowStart, field.TypeTime, value)
		_node.SessionWindowStart = &value
	}
	if value, ok := _c.mutation.SessionWindowEnd(); ok {
		_spec.SetField(account.FieldSessionWindowEnd, field.TypeTime, value)
		_node.SessionWindowEnd = &value
	}
	if value, ok := _c.mutation.SessionWindowStatus(); ok {
		_spec.SetField(account.FieldSessionWindowStatus, field.TypeString, value)
		_node.SessionWindowStatus = &value
	}
	if nodes := _c.mutation.GroupsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   account.GroupsTable,
			Columns: account.GroupsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _c.config, mutation: newAccountGroupMutation(_c.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_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.Account.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.AccountUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *AccountCreate) OnConflict(opts ...sql.ConflictOption) *AccountUpsertOne {
	_c.conflict = opts
	return &AccountUpsertOne{
		create: _c,
	}
}

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

type (
	// AccountUpsertOne is the builder for "upsert"-ing
	//  one Account node.
	AccountUpsertOne struct {
		create *AccountCreate
	}

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *AccountUpsert) SetDeletedAt(v time.Time) *AccountUpsert {
	u.Set(account.FieldDeletedAt, v)
	return u
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *AccountUpsert) UpdateDeletedAt() *AccountUpsert {
	u.SetExcluded(account.FieldDeletedAt)
	return u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *AccountUpsert) ClearDeletedAt() *AccountUpsert {
	u.SetNull(account.FieldDeletedAt)
	return u
}

// SetName sets the "name" field.
func (u *AccountUpsert) SetName(v string) *AccountUpsert {
	u.Set(account.FieldName, v)
	return u
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *AccountUpsert) UpdateName() *AccountUpsert {
	u.SetExcluded(account.FieldName)
	return u
}

// SetPlatform sets the "platform" field.
func (u *AccountUpsert) SetPlatform(v string) *AccountUpsert {
	u.Set(account.FieldPlatform, v)
	return u
}

// UpdatePlatform sets the "platform" field to the value that was provided on create.
func (u *AccountUpsert) UpdatePlatform() *AccountUpsert {
	u.SetExcluded(account.FieldPlatform)
	return u
}

// SetType sets the "type" field.
func (u *AccountUpsert) SetType(v string) *AccountUpsert {
	u.Set(account.FieldType, v)
	return u
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *AccountUpsert) UpdateType() *AccountUpsert {
	u.SetExcluded(account.FieldType)
	return u
}

// SetCredentials sets the "credentials" field.
func (u *AccountUpsert) SetCredentials(v map[string]interface{}) *AccountUpsert {
	u.Set(account.FieldCredentials, v)
	return u
}

// UpdateCredentials sets the "credentials" field to the value that was provided on create.
func (u *AccountUpsert) UpdateCredentials() *AccountUpsert {
	u.SetExcluded(account.FieldCredentials)
	return u
}

// SetExtra sets the "extra" field.
func (u *AccountUpsert) SetExtra(v map[string]interface{}) *AccountUpsert {
	u.Set(account.FieldExtra, v)
	return u
}

// UpdateExtra sets the "extra" field to the value that was provided on create.
func (u *AccountUpsert) UpdateExtra() *AccountUpsert {
	u.SetExcluded(account.FieldExtra)
	return u
}

// SetProxyID sets the "proxy_id" field.
func (u *AccountUpsert) SetProxyID(v int64) *AccountUpsert {
	u.Set(account.FieldProxyID, v)
	return u
}

// UpdateProxyID sets the "proxy_id" field to the value that was provided on create.
func (u *AccountUpsert) UpdateProxyID() *AccountUpsert {
	u.SetExcluded(account.FieldProxyID)
	return u
}

// AddProxyID adds v to the "proxy_id" field.
func (u *AccountUpsert) AddProxyID(v int64) *AccountUpsert {
	u.Add(account.FieldProxyID, v)
	return u
}

// ClearProxyID clears the value of the "proxy_id" field.
func (u *AccountUpsert) ClearProxyID() *AccountUpsert {
	u.SetNull(account.FieldProxyID)
	return u
}

// SetConcurrency sets the "concurrency" field.
func (u *AccountUpsert) SetConcurrency(v int) *AccountUpsert {
	u.Set(account.FieldConcurrency, v)
	return u
}

// UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
func (u *AccountUpsert) UpdateConcurrency() *AccountUpsert {
	u.SetExcluded(account.FieldConcurrency)
	return u
}

// AddConcurrency adds v to the "concurrency" field.
func (u *AccountUpsert) AddConcurrency(v int) *AccountUpsert {
	u.Add(account.FieldConcurrency, v)
	return u
}

// SetPriority sets the "priority" field.
func (u *AccountUpsert) SetPriority(v int) *AccountUpsert {
	u.Set(account.FieldPriority, v)
	return u
}

// UpdatePriority sets the "priority" field to the value that was provided on create.
func (u *AccountUpsert) UpdatePriority() *AccountUpsert {
	u.SetExcluded(account.FieldPriority)
	return u
}

// AddPriority adds v to the "priority" field.
func (u *AccountUpsert) AddPriority(v int) *AccountUpsert {
	u.Add(account.FieldPriority, v)
	return u
}

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

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

// SetErrorMessage sets the "error_message" field.
func (u *AccountUpsert) SetErrorMessage(v string) *AccountUpsert {
	u.Set(account.FieldErrorMessage, v)
	return u
}

// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func (u *AccountUpsert) UpdateErrorMessage() *AccountUpsert {
	u.SetExcluded(account.FieldErrorMessage)
	return u
}

// ClearErrorMessage clears the value of the "error_message" field.
func (u *AccountUpsert) ClearErrorMessage() *AccountUpsert {
	u.SetNull(account.FieldErrorMessage)
	return u
}

// SetLastUsedAt sets the "last_used_at" field.
func (u *AccountUpsert) SetLastUsedAt(v time.Time) *AccountUpsert {
	u.Set(account.FieldLastUsedAt, v)
	return u
}

// UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
func (u *AccountUpsert) UpdateLastUsedAt() *AccountUpsert {
	u.SetExcluded(account.FieldLastUsedAt)
	return u
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (u *AccountUpsert) ClearLastUsedAt() *AccountUpsert {
	u.SetNull(account.FieldLastUsedAt)
	return u
}

// SetSchedulable sets the "schedulable" field.
func (u *AccountUpsert) SetSchedulable(v bool) *AccountUpsert {
	u.Set(account.FieldSchedulable, v)
	return u
}

// UpdateSchedulable sets the "schedulable" field to the value that was provided on create.
func (u *AccountUpsert) UpdateSchedulable() *AccountUpsert {
	u.SetExcluded(account.FieldSchedulable)
	return u
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (u *AccountUpsert) SetRateLimitedAt(v time.Time) *AccountUpsert {
	u.Set(account.FieldRateLimitedAt, v)
	return u
}

// UpdateRateLimitedAt sets the "rate_limited_at" field to the value that was provided on create.
func (u *AccountUpsert) UpdateRateLimitedAt() *AccountUpsert {
	u.SetExcluded(account.FieldRateLimitedAt)
	return u
}

// ClearRateLimitedAt clears the value of the "rate_limited_at" field.
func (u *AccountUpsert) ClearRateLimitedAt() *AccountUpsert {
	u.SetNull(account.FieldRateLimitedAt)
	return u
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (u *AccountUpsert) SetRateLimitResetAt(v time.Time) *AccountUpsert {
	u.Set(account.FieldRateLimitResetAt, v)
	return u
}

// UpdateRateLimitResetAt sets the "rate_limit_reset_at" field to the value that was provided on create.
func (u *AccountUpsert) UpdateRateLimitResetAt() *AccountUpsert {
	u.SetExcluded(account.FieldRateLimitResetAt)
	return u
}

// ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
func (u *AccountUpsert) ClearRateLimitResetAt() *AccountUpsert {
	u.SetNull(account.FieldRateLimitResetAt)
	return u
}

// SetOverloadUntil sets the "overload_until" field.
func (u *AccountUpsert) SetOverloadUntil(v time.Time) *AccountUpsert {
	u.Set(account.FieldOverloadUntil, v)
	return u
}

// UpdateOverloadUntil sets the "overload_until" field to the value that was provided on create.
func (u *AccountUpsert) UpdateOverloadUntil() *AccountUpsert {
	u.SetExcluded(account.FieldOverloadUntil)
	return u
}

// ClearOverloadUntil clears the value of the "overload_until" field.
func (u *AccountUpsert) ClearOverloadUntil() *AccountUpsert {
	u.SetNull(account.FieldOverloadUntil)
	return u
}

// SetSessionWindowStart sets the "session_window_start" field.
func (u *AccountUpsert) SetSessionWindowStart(v time.Time) *AccountUpsert {
	u.Set(account.FieldSessionWindowStart, v)
	return u
}

// UpdateSessionWindowStart sets the "session_window_start" field to the value that was provided on create.
func (u *AccountUpsert) UpdateSessionWindowStart() *AccountUpsert {
	u.SetExcluded(account.FieldSessionWindowStart)
	return u
}

// ClearSessionWindowStart clears the value of the "session_window_start" field.
func (u *AccountUpsert) ClearSessionWindowStart() *AccountUpsert {
	u.SetNull(account.FieldSessionWindowStart)
	return u
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (u *AccountUpsert) SetSessionWindowEnd(v time.Time) *AccountUpsert {
	u.Set(account.FieldSessionWindowEnd, v)
	return u
}

// UpdateSessionWindowEnd sets the "session_window_end" field to the value that was provided on create.
func (u *AccountUpsert) UpdateSessionWindowEnd() *AccountUpsert {
	u.SetExcluded(account.FieldSessionWindowEnd)
	return u
}

// ClearSessionWindowEnd clears the value of the "session_window_end" field.
func (u *AccountUpsert) ClearSessionWindowEnd() *AccountUpsert {
	u.SetNull(account.FieldSessionWindowEnd)
	return u
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (u *AccountUpsert) SetSessionWindowStatus(v string) *AccountUpsert {
	u.Set(account.FieldSessionWindowStatus, v)
	return u
}

// UpdateSessionWindowStatus sets the "session_window_status" field to the value that was provided on create.
func (u *AccountUpsert) UpdateSessionWindowStatus() *AccountUpsert {
	u.SetExcluded(account.FieldSessionWindowStatus)
	return u
}

// ClearSessionWindowStatus clears the value of the "session_window_status" field.
func (u *AccountUpsert) ClearSessionWindowStatus() *AccountUpsert {
	u.SetNull(account.FieldSessionWindowStatus)
	return u
}

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *AccountUpsertOne) SetDeletedAt(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateDeletedAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *AccountUpsertOne) ClearDeletedAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearDeletedAt()
	})
}

// SetName sets the "name" field.
func (u *AccountUpsertOne) SetName(v string) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateName() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateName()
	})
}

// SetPlatform sets the "platform" field.
func (u *AccountUpsertOne) SetPlatform(v string) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetPlatform(v)
	})
}

// UpdatePlatform sets the "platform" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdatePlatform() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdatePlatform()
	})
}

// SetType sets the "type" field.
func (u *AccountUpsertOne) SetType(v string) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateType() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateType()
	})
}

// SetCredentials sets the "credentials" field.
func (u *AccountUpsertOne) SetCredentials(v map[string]interface{}) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetCredentials(v)
	})
}

// UpdateCredentials sets the "credentials" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateCredentials() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateCredentials()
	})
}

// SetExtra sets the "extra" field.
func (u *AccountUpsertOne) SetExtra(v map[string]interface{}) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetExtra(v)
	})
}

// UpdateExtra sets the "extra" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateExtra() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateExtra()
	})
}

// SetProxyID sets the "proxy_id" field.
func (u *AccountUpsertOne) SetProxyID(v int64) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetProxyID(v)
	})
}

// AddProxyID adds v to the "proxy_id" field.
func (u *AccountUpsertOne) AddProxyID(v int64) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.AddProxyID(v)
	})
}

// UpdateProxyID sets the "proxy_id" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateProxyID() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateProxyID()
	})
}

// ClearProxyID clears the value of the "proxy_id" field.
func (u *AccountUpsertOne) ClearProxyID() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearProxyID()
	})
}

// SetConcurrency sets the "concurrency" field.
func (u *AccountUpsertOne) SetConcurrency(v int) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetConcurrency(v)
	})
}

// AddConcurrency adds v to the "concurrency" field.
func (u *AccountUpsertOne) AddConcurrency(v int) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.AddConcurrency(v)
	})
}

// UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateConcurrency() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateConcurrency()
	})
}

// SetPriority sets the "priority" field.
func (u *AccountUpsertOne) SetPriority(v int) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetPriority(v)
	})
}

// AddPriority adds v to the "priority" field.
func (u *AccountUpsertOne) AddPriority(v int) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.AddPriority(v)
	})
}

// UpdatePriority sets the "priority" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdatePriority() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdatePriority()
	})
}

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

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

// SetErrorMessage sets the "error_message" field.
func (u *AccountUpsertOne) SetErrorMessage(v string) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetErrorMessage(v)
	})
}

// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateErrorMessage() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateErrorMessage()
	})
}

// ClearErrorMessage clears the value of the "error_message" field.
func (u *AccountUpsertOne) ClearErrorMessage() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearErrorMessage()
	})
}

// SetLastUsedAt sets the "last_used_at" field.
func (u *AccountUpsertOne) SetLastUsedAt(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetLastUsedAt(v)
	})
}

// UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateLastUsedAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateLastUsedAt()
	})
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (u *AccountUpsertOne) ClearLastUsedAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearLastUsedAt()
	})
}

// SetSchedulable sets the "schedulable" field.
func (u *AccountUpsertOne) SetSchedulable(v bool) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetSchedulable(v)
	})
}

// UpdateSchedulable sets the "schedulable" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateSchedulable() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSchedulable()
	})
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (u *AccountUpsertOne) SetRateLimitedAt(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetRateLimitedAt(v)
	})
}

// UpdateRateLimitedAt sets the "rate_limited_at" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateRateLimitedAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateRateLimitedAt()
	})
}

// ClearRateLimitedAt clears the value of the "rate_limited_at" field.
func (u *AccountUpsertOne) ClearRateLimitedAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearRateLimitedAt()
	})
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (u *AccountUpsertOne) SetRateLimitResetAt(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetRateLimitResetAt(v)
	})
}

// UpdateRateLimitResetAt sets the "rate_limit_reset_at" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateRateLimitResetAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateRateLimitResetAt()
	})
}

// ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
func (u *AccountUpsertOne) ClearRateLimitResetAt() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearRateLimitResetAt()
	})
}

// SetOverloadUntil sets the "overload_until" field.
func (u *AccountUpsertOne) SetOverloadUntil(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetOverloadUntil(v)
	})
}

// UpdateOverloadUntil sets the "overload_until" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateOverloadUntil() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateOverloadUntil()
	})
}

// ClearOverloadUntil clears the value of the "overload_until" field.
func (u *AccountUpsertOne) ClearOverloadUntil() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearOverloadUntil()
	})
}

// SetSessionWindowStart sets the "session_window_start" field.
func (u *AccountUpsertOne) SetSessionWindowStart(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetSessionWindowStart(v)
	})
}

// UpdateSessionWindowStart sets the "session_window_start" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateSessionWindowStart() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSessionWindowStart()
	})
}

// ClearSessionWindowStart clears the value of the "session_window_start" field.
func (u *AccountUpsertOne) ClearSessionWindowStart() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearSessionWindowStart()
	})
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (u *AccountUpsertOne) SetSessionWindowEnd(v time.Time) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetSessionWindowEnd(v)
	})
}

// UpdateSessionWindowEnd sets the "session_window_end" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateSessionWindowEnd() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSessionWindowEnd()
	})
}

// ClearSessionWindowEnd clears the value of the "session_window_end" field.
func (u *AccountUpsertOne) ClearSessionWindowEnd() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearSessionWindowEnd()
	})
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (u *AccountUpsertOne) SetSessionWindowStatus(v string) *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.SetSessionWindowStatus(v)
	})
}

// UpdateSessionWindowStatus sets the "session_window_status" field to the value that was provided on create.
func (u *AccountUpsertOne) UpdateSessionWindowStatus() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSessionWindowStatus()
	})
}

// ClearSessionWindowStatus clears the value of the "session_window_status" field.
func (u *AccountUpsertOne) ClearSessionWindowStatus() *AccountUpsertOne {
	return u.Update(func(s *AccountUpsert) {
		s.ClearSessionWindowStatus()
	})
}

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

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

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

// Save creates the Account entities in the database.
func (_c *AccountCreateBulk) Save(ctx context.Context) ([]*Account, error) {
	if _c.err != nil {
		return nil, _c.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
	nodes := make([]*Account, 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.(*AccountMutation)
				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 *AccountCreateBulk) SaveX(ctx context.Context) []*Account {
	v, err := _c.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

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

// ExecX is like Exec, but panics if an error occurs.
func (_c *AccountCreateBulk) 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.Account.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.AccountUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (_c *AccountCreateBulk) OnConflict(opts ...sql.ConflictOption) *AccountUpsertBulk {
	_c.conflict = opts
	return &AccountUpsertBulk{
		create: _c,
	}
}

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

// AccountUpsertBulk is the builder for "upsert"-ing
// a bulk of Account nodes.
type AccountUpsertBulk struct {
	create *AccountCreateBulk
}

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (u *AccountUpsertBulk) SetDeletedAt(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateDeletedAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *AccountUpsertBulk) ClearDeletedAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearDeletedAt()
	})
}

// SetName sets the "name" field.
func (u *AccountUpsertBulk) SetName(v string) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateName() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateName()
	})
}

// SetPlatform sets the "platform" field.
func (u *AccountUpsertBulk) SetPlatform(v string) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetPlatform(v)
	})
}

// UpdatePlatform sets the "platform" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdatePlatform() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdatePlatform()
	})
}

// SetType sets the "type" field.
func (u *AccountUpsertBulk) SetType(v string) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateType() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateType()
	})
}

// SetCredentials sets the "credentials" field.
func (u *AccountUpsertBulk) SetCredentials(v map[string]interface{}) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetCredentials(v)
	})
}

// UpdateCredentials sets the "credentials" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateCredentials() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateCredentials()
	})
}

// SetExtra sets the "extra" field.
func (u *AccountUpsertBulk) SetExtra(v map[string]interface{}) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetExtra(v)
	})
}

// UpdateExtra sets the "extra" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateExtra() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateExtra()
	})
}

// SetProxyID sets the "proxy_id" field.
func (u *AccountUpsertBulk) SetProxyID(v int64) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetProxyID(v)
	})
}

// AddProxyID adds v to the "proxy_id" field.
func (u *AccountUpsertBulk) AddProxyID(v int64) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.AddProxyID(v)
	})
}

// UpdateProxyID sets the "proxy_id" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateProxyID() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateProxyID()
	})
}

// ClearProxyID clears the value of the "proxy_id" field.
func (u *AccountUpsertBulk) ClearProxyID() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearProxyID()
	})
}

// SetConcurrency sets the "concurrency" field.
func (u *AccountUpsertBulk) SetConcurrency(v int) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetConcurrency(v)
	})
}

// AddConcurrency adds v to the "concurrency" field.
func (u *AccountUpsertBulk) AddConcurrency(v int) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.AddConcurrency(v)
	})
}

// UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateConcurrency() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateConcurrency()
	})
}

// SetPriority sets the "priority" field.
func (u *AccountUpsertBulk) SetPriority(v int) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetPriority(v)
	})
}

// AddPriority adds v to the "priority" field.
func (u *AccountUpsertBulk) AddPriority(v int) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.AddPriority(v)
	})
}

// UpdatePriority sets the "priority" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdatePriority() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdatePriority()
	})
}

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

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

// SetErrorMessage sets the "error_message" field.
func (u *AccountUpsertBulk) SetErrorMessage(v string) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetErrorMessage(v)
	})
}

// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateErrorMessage() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateErrorMessage()
	})
}

// ClearErrorMessage clears the value of the "error_message" field.
func (u *AccountUpsertBulk) ClearErrorMessage() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearErrorMessage()
	})
}

// SetLastUsedAt sets the "last_used_at" field.
func (u *AccountUpsertBulk) SetLastUsedAt(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetLastUsedAt(v)
	})
}

// UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateLastUsedAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateLastUsedAt()
	})
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (u *AccountUpsertBulk) ClearLastUsedAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearLastUsedAt()
	})
}

// SetSchedulable sets the "schedulable" field.
func (u *AccountUpsertBulk) SetSchedulable(v bool) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetSchedulable(v)
	})
}

// UpdateSchedulable sets the "schedulable" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateSchedulable() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSchedulable()
	})
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (u *AccountUpsertBulk) SetRateLimitedAt(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetRateLimitedAt(v)
	})
}

// UpdateRateLimitedAt sets the "rate_limited_at" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateRateLimitedAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateRateLimitedAt()
	})
}

// ClearRateLimitedAt clears the value of the "rate_limited_at" field.
func (u *AccountUpsertBulk) ClearRateLimitedAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearRateLimitedAt()
	})
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (u *AccountUpsertBulk) SetRateLimitResetAt(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetRateLimitResetAt(v)
	})
}

// UpdateRateLimitResetAt sets the "rate_limit_reset_at" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateRateLimitResetAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateRateLimitResetAt()
	})
}

// ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
func (u *AccountUpsertBulk) ClearRateLimitResetAt() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearRateLimitResetAt()
	})
}

// SetOverloadUntil sets the "overload_until" field.
func (u *AccountUpsertBulk) SetOverloadUntil(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetOverloadUntil(v)
	})
}

// UpdateOverloadUntil sets the "overload_until" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateOverloadUntil() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateOverloadUntil()
	})
}

// ClearOverloadUntil clears the value of the "overload_until" field.
func (u *AccountUpsertBulk) ClearOverloadUntil() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearOverloadUntil()
	})
}

// SetSessionWindowStart sets the "session_window_start" field.
func (u *AccountUpsertBulk) SetSessionWindowStart(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetSessionWindowStart(v)
	})
}

// UpdateSessionWindowStart sets the "session_window_start" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateSessionWindowStart() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSessionWindowStart()
	})
}

// ClearSessionWindowStart clears the value of the "session_window_start" field.
func (u *AccountUpsertBulk) ClearSessionWindowStart() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearSessionWindowStart()
	})
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (u *AccountUpsertBulk) SetSessionWindowEnd(v time.Time) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetSessionWindowEnd(v)
	})
}

// UpdateSessionWindowEnd sets the "session_window_end" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateSessionWindowEnd() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSessionWindowEnd()
	})
}

// ClearSessionWindowEnd clears the value of the "session_window_end" field.
func (u *AccountUpsertBulk) ClearSessionWindowEnd() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearSessionWindowEnd()
	})
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (u *AccountUpsertBulk) SetSessionWindowStatus(v string) *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.SetSessionWindowStatus(v)
	})
}

// UpdateSessionWindowStatus sets the "session_window_status" field to the value that was provided on create.
func (u *AccountUpsertBulk) UpdateSessionWindowStatus() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.UpdateSessionWindowStatus()
	})
}

// ClearSessionWindowStatus clears the value of the "session_window_status" field.
func (u *AccountUpsertBulk) ClearSessionWindowStatus() *AccountUpsertBulk {
	return u.Update(func(s *AccountUpsert) {
		s.ClearSessionWindowStatus()
	})
}

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

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