// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/custom_types"
	"wechat-api/ent/usagedetail"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// UsageDetailCreate is the builder for creating a UsageDetail entity.
type UsageDetailCreate struct {
	config
	mutation *UsageDetailMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (udc *UsageDetailCreate) SetCreatedAt(t time.Time) *UsageDetailCreate {
	udc.mutation.SetCreatedAt(t)
	return udc
}

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

// SetUpdatedAt sets the "updated_at" field.
func (udc *UsageDetailCreate) SetUpdatedAt(t time.Time) *UsageDetailCreate {
	udc.mutation.SetUpdatedAt(t)
	return udc
}

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

// SetStatus sets the "status" field.
func (udc *UsageDetailCreate) SetStatus(u uint8) *UsageDetailCreate {
	udc.mutation.SetStatus(u)
	return udc
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableStatus(u *uint8) *UsageDetailCreate {
	if u != nil {
		udc.SetStatus(*u)
	}
	return udc
}

// SetType sets the "type" field.
func (udc *UsageDetailCreate) SetType(i int) *UsageDetailCreate {
	udc.mutation.SetType(i)
	return udc
}

// SetNillableType sets the "type" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableType(i *int) *UsageDetailCreate {
	if i != nil {
		udc.SetType(*i)
	}
	return udc
}

// SetBotID sets the "bot_id" field.
func (udc *UsageDetailCreate) SetBotID(s string) *UsageDetailCreate {
	udc.mutation.SetBotID(s)
	return udc
}

// SetNillableBotID sets the "bot_id" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableBotID(s *string) *UsageDetailCreate {
	if s != nil {
		udc.SetBotID(*s)
	}
	return udc
}

// SetReceiverID sets the "receiver_id" field.
func (udc *UsageDetailCreate) SetReceiverID(s string) *UsageDetailCreate {
	udc.mutation.SetReceiverID(s)
	return udc
}

// SetNillableReceiverID sets the "receiver_id" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableReceiverID(s *string) *UsageDetailCreate {
	if s != nil {
		udc.SetReceiverID(*s)
	}
	return udc
}

// SetApp sets the "app" field.
func (udc *UsageDetailCreate) SetApp(i int) *UsageDetailCreate {
	udc.mutation.SetApp(i)
	return udc
}

// SetNillableApp sets the "app" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableApp(i *int) *UsageDetailCreate {
	if i != nil {
		udc.SetApp(*i)
	}
	return udc
}

// SetSessionID sets the "session_id" field.
func (udc *UsageDetailCreate) SetSessionID(u uint64) *UsageDetailCreate {
	udc.mutation.SetSessionID(u)
	return udc
}

// SetNillableSessionID sets the "session_id" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableSessionID(u *uint64) *UsageDetailCreate {
	if u != nil {
		udc.SetSessionID(*u)
	}
	return udc
}

// SetRequest sets the "request" field.
func (udc *UsageDetailCreate) SetRequest(s string) *UsageDetailCreate {
	udc.mutation.SetRequest(s)
	return udc
}

// SetNillableRequest sets the "request" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableRequest(s *string) *UsageDetailCreate {
	if s != nil {
		udc.SetRequest(*s)
	}
	return udc
}

// SetResponse sets the "response" field.
func (udc *UsageDetailCreate) SetResponse(s string) *UsageDetailCreate {
	udc.mutation.SetResponse(s)
	return udc
}

// SetNillableResponse sets the "response" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableResponse(s *string) *UsageDetailCreate {
	if s != nil {
		udc.SetResponse(*s)
	}
	return udc
}

// SetOriginalData sets the "original_data" field.
func (udc *UsageDetailCreate) SetOriginalData(ctd custom_types.OriginalData) *UsageDetailCreate {
	udc.mutation.SetOriginalData(ctd)
	return udc
}

// SetTotalTokens sets the "total_tokens" field.
func (udc *UsageDetailCreate) SetTotalTokens(u uint64) *UsageDetailCreate {
	udc.mutation.SetTotalTokens(u)
	return udc
}

// SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableTotalTokens(u *uint64) *UsageDetailCreate {
	if u != nil {
		udc.SetTotalTokens(*u)
	}
	return udc
}

// SetPromptTokens sets the "prompt_tokens" field.
func (udc *UsageDetailCreate) SetPromptTokens(u uint64) *UsageDetailCreate {
	udc.mutation.SetPromptTokens(u)
	return udc
}

// SetNillablePromptTokens sets the "prompt_tokens" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillablePromptTokens(u *uint64) *UsageDetailCreate {
	if u != nil {
		udc.SetPromptTokens(*u)
	}
	return udc
}

// SetCompletionTokens sets the "completion_tokens" field.
func (udc *UsageDetailCreate) SetCompletionTokens(u uint64) *UsageDetailCreate {
	udc.mutation.SetCompletionTokens(u)
	return udc
}

// SetNillableCompletionTokens sets the "completion_tokens" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableCompletionTokens(u *uint64) *UsageDetailCreate {
	if u != nil {
		udc.SetCompletionTokens(*u)
	}
	return udc
}

// SetOrganizationID sets the "organization_id" field.
func (udc *UsageDetailCreate) SetOrganizationID(u uint64) *UsageDetailCreate {
	udc.mutation.SetOrganizationID(u)
	return udc
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (udc *UsageDetailCreate) SetNillableOrganizationID(u *uint64) *UsageDetailCreate {
	if u != nil {
		udc.SetOrganizationID(*u)
	}
	return udc
}

// SetID sets the "id" field.
func (udc *UsageDetailCreate) SetID(u uint64) *UsageDetailCreate {
	udc.mutation.SetID(u)
	return udc
}

// Mutation returns the UsageDetailMutation object of the builder.
func (udc *UsageDetailCreate) Mutation() *UsageDetailMutation {
	return udc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (udc *UsageDetailCreate) defaults() {
	if _, ok := udc.mutation.CreatedAt(); !ok {
		v := usagedetail.DefaultCreatedAt()
		udc.mutation.SetCreatedAt(v)
	}
	if _, ok := udc.mutation.UpdatedAt(); !ok {
		v := usagedetail.DefaultUpdatedAt()
		udc.mutation.SetUpdatedAt(v)
	}
	if _, ok := udc.mutation.Status(); !ok {
		v := usagedetail.DefaultStatus
		udc.mutation.SetStatus(v)
	}
	if _, ok := udc.mutation.GetType(); !ok {
		v := usagedetail.DefaultType
		udc.mutation.SetType(v)
	}
	if _, ok := udc.mutation.BotID(); !ok {
		v := usagedetail.DefaultBotID
		udc.mutation.SetBotID(v)
	}
	if _, ok := udc.mutation.ReceiverID(); !ok {
		v := usagedetail.DefaultReceiverID
		udc.mutation.SetReceiverID(v)
	}
	if _, ok := udc.mutation.App(); !ok {
		v := usagedetail.DefaultApp
		udc.mutation.SetApp(v)
	}
	if _, ok := udc.mutation.SessionID(); !ok {
		v := usagedetail.DefaultSessionID
		udc.mutation.SetSessionID(v)
	}
	if _, ok := udc.mutation.Request(); !ok {
		v := usagedetail.DefaultRequest
		udc.mutation.SetRequest(v)
	}
	if _, ok := udc.mutation.Response(); !ok {
		v := usagedetail.DefaultResponse
		udc.mutation.SetResponse(v)
	}
	if _, ok := udc.mutation.TotalTokens(); !ok {
		v := usagedetail.DefaultTotalTokens
		udc.mutation.SetTotalTokens(v)
	}
	if _, ok := udc.mutation.PromptTokens(); !ok {
		v := usagedetail.DefaultPromptTokens
		udc.mutation.SetPromptTokens(v)
	}
	if _, ok := udc.mutation.CompletionTokens(); !ok {
		v := usagedetail.DefaultCompletionTokens
		udc.mutation.SetCompletionTokens(v)
	}
	if _, ok := udc.mutation.OrganizationID(); !ok {
		v := usagedetail.DefaultOrganizationID
		udc.mutation.SetOrganizationID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (udc *UsageDetailCreate) check() error {
	if _, ok := udc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UsageDetail.created_at"`)}
	}
	if _, ok := udc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UsageDetail.updated_at"`)}
	}
	if _, ok := udc.mutation.BotID(); !ok {
		return &ValidationError{Name: "bot_id", err: errors.New(`ent: missing required field "UsageDetail.bot_id"`)}
	}
	if _, ok := udc.mutation.ReceiverID(); !ok {
		return &ValidationError{Name: "receiver_id", err: errors.New(`ent: missing required field "UsageDetail.receiver_id"`)}
	}
	if _, ok := udc.mutation.Request(); !ok {
		return &ValidationError{Name: "request", err: errors.New(`ent: missing required field "UsageDetail.request"`)}
	}
	if _, ok := udc.mutation.Response(); !ok {
		return &ValidationError{Name: "response", err: errors.New(`ent: missing required field "UsageDetail.response"`)}
	}
	if _, ok := udc.mutation.OriginalData(); !ok {
		return &ValidationError{Name: "original_data", err: errors.New(`ent: missing required field "UsageDetail.original_data"`)}
	}
	return nil
}

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

func (udc *UsageDetailCreate) createSpec() (*UsageDetail, *sqlgraph.CreateSpec) {
	var (
		_node = &UsageDetail{config: udc.config}
		_spec = sqlgraph.NewCreateSpec(usagedetail.Table, sqlgraph.NewFieldSpec(usagedetail.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = udc.conflict
	if id, ok := udc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := udc.mutation.CreatedAt(); ok {
		_spec.SetField(usagedetail.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := udc.mutation.UpdatedAt(); ok {
		_spec.SetField(usagedetail.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := udc.mutation.Status(); ok {
		_spec.SetField(usagedetail.FieldStatus, field.TypeUint8, value)
		_node.Status = value
	}
	if value, ok := udc.mutation.GetType(); ok {
		_spec.SetField(usagedetail.FieldType, field.TypeInt, value)
		_node.Type = value
	}
	if value, ok := udc.mutation.BotID(); ok {
		_spec.SetField(usagedetail.FieldBotID, field.TypeString, value)
		_node.BotID = value
	}
	if value, ok := udc.mutation.ReceiverID(); ok {
		_spec.SetField(usagedetail.FieldReceiverID, field.TypeString, value)
		_node.ReceiverID = value
	}
	if value, ok := udc.mutation.App(); ok {
		_spec.SetField(usagedetail.FieldApp, field.TypeInt, value)
		_node.App = value
	}
	if value, ok := udc.mutation.SessionID(); ok {
		_spec.SetField(usagedetail.FieldSessionID, field.TypeUint64, value)
		_node.SessionID = value
	}
	if value, ok := udc.mutation.Request(); ok {
		_spec.SetField(usagedetail.FieldRequest, field.TypeString, value)
		_node.Request = value
	}
	if value, ok := udc.mutation.Response(); ok {
		_spec.SetField(usagedetail.FieldResponse, field.TypeString, value)
		_node.Response = value
	}
	if value, ok := udc.mutation.OriginalData(); ok {
		_spec.SetField(usagedetail.FieldOriginalData, field.TypeJSON, value)
		_node.OriginalData = value
	}
	if value, ok := udc.mutation.TotalTokens(); ok {
		_spec.SetField(usagedetail.FieldTotalTokens, field.TypeUint64, value)
		_node.TotalTokens = value
	}
	if value, ok := udc.mutation.PromptTokens(); ok {
		_spec.SetField(usagedetail.FieldPromptTokens, field.TypeUint64, value)
		_node.PromptTokens = value
	}
	if value, ok := udc.mutation.CompletionTokens(); ok {
		_spec.SetField(usagedetail.FieldCompletionTokens, field.TypeUint64, value)
		_node.CompletionTokens = value
	}
	if value, ok := udc.mutation.OrganizationID(); ok {
		_spec.SetField(usagedetail.FieldOrganizationID, field.TypeUint64, value)
		_node.OrganizationID = value
	}
	return _node, _spec
}

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

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

type (
	// UsageDetailUpsertOne is the builder for "upsert"-ing
	//  one UsageDetail node.
	UsageDetailUpsertOne struct {
		create *UsageDetailCreate
	}

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

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

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

// SetStatus sets the "status" field.
func (u *UsageDetailUpsert) SetStatus(v uint8) *UsageDetailUpsert {
	u.Set(usagedetail.FieldStatus, v)
	return u
}

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

// AddStatus adds v to the "status" field.
func (u *UsageDetailUpsert) AddStatus(v uint8) *UsageDetailUpsert {
	u.Add(usagedetail.FieldStatus, v)
	return u
}

// ClearStatus clears the value of the "status" field.
func (u *UsageDetailUpsert) ClearStatus() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldStatus)
	return u
}

// SetType sets the "type" field.
func (u *UsageDetailUpsert) SetType(v int) *UsageDetailUpsert {
	u.Set(usagedetail.FieldType, v)
	return u
}

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

// AddType adds v to the "type" field.
func (u *UsageDetailUpsert) AddType(v int) *UsageDetailUpsert {
	u.Add(usagedetail.FieldType, v)
	return u
}

// ClearType clears the value of the "type" field.
func (u *UsageDetailUpsert) ClearType() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldType)
	return u
}

// SetBotID sets the "bot_id" field.
func (u *UsageDetailUpsert) SetBotID(v string) *UsageDetailUpsert {
	u.Set(usagedetail.FieldBotID, v)
	return u
}

// UpdateBotID sets the "bot_id" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateBotID() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldBotID)
	return u
}

// SetReceiverID sets the "receiver_id" field.
func (u *UsageDetailUpsert) SetReceiverID(v string) *UsageDetailUpsert {
	u.Set(usagedetail.FieldReceiverID, v)
	return u
}

// UpdateReceiverID sets the "receiver_id" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateReceiverID() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldReceiverID)
	return u
}

// SetApp sets the "app" field.
func (u *UsageDetailUpsert) SetApp(v int) *UsageDetailUpsert {
	u.Set(usagedetail.FieldApp, v)
	return u
}

// UpdateApp sets the "app" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateApp() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldApp)
	return u
}

// AddApp adds v to the "app" field.
func (u *UsageDetailUpsert) AddApp(v int) *UsageDetailUpsert {
	u.Add(usagedetail.FieldApp, v)
	return u
}

// ClearApp clears the value of the "app" field.
func (u *UsageDetailUpsert) ClearApp() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldApp)
	return u
}

// SetSessionID sets the "session_id" field.
func (u *UsageDetailUpsert) SetSessionID(v uint64) *UsageDetailUpsert {
	u.Set(usagedetail.FieldSessionID, v)
	return u
}

// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateSessionID() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldSessionID)
	return u
}

// AddSessionID adds v to the "session_id" field.
func (u *UsageDetailUpsert) AddSessionID(v uint64) *UsageDetailUpsert {
	u.Add(usagedetail.FieldSessionID, v)
	return u
}

// ClearSessionID clears the value of the "session_id" field.
func (u *UsageDetailUpsert) ClearSessionID() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldSessionID)
	return u
}

// SetRequest sets the "request" field.
func (u *UsageDetailUpsert) SetRequest(v string) *UsageDetailUpsert {
	u.Set(usagedetail.FieldRequest, v)
	return u
}

// UpdateRequest sets the "request" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateRequest() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldRequest)
	return u
}

// SetResponse sets the "response" field.
func (u *UsageDetailUpsert) SetResponse(v string) *UsageDetailUpsert {
	u.Set(usagedetail.FieldResponse, v)
	return u
}

// UpdateResponse sets the "response" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateResponse() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldResponse)
	return u
}

// SetOriginalData sets the "original_data" field.
func (u *UsageDetailUpsert) SetOriginalData(v custom_types.OriginalData) *UsageDetailUpsert {
	u.Set(usagedetail.FieldOriginalData, v)
	return u
}

// UpdateOriginalData sets the "original_data" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateOriginalData() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldOriginalData)
	return u
}

// SetTotalTokens sets the "total_tokens" field.
func (u *UsageDetailUpsert) SetTotalTokens(v uint64) *UsageDetailUpsert {
	u.Set(usagedetail.FieldTotalTokens, v)
	return u
}

// UpdateTotalTokens sets the "total_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateTotalTokens() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldTotalTokens)
	return u
}

// AddTotalTokens adds v to the "total_tokens" field.
func (u *UsageDetailUpsert) AddTotalTokens(v uint64) *UsageDetailUpsert {
	u.Add(usagedetail.FieldTotalTokens, v)
	return u
}

// ClearTotalTokens clears the value of the "total_tokens" field.
func (u *UsageDetailUpsert) ClearTotalTokens() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldTotalTokens)
	return u
}

// SetPromptTokens sets the "prompt_tokens" field.
func (u *UsageDetailUpsert) SetPromptTokens(v uint64) *UsageDetailUpsert {
	u.Set(usagedetail.FieldPromptTokens, v)
	return u
}

// UpdatePromptTokens sets the "prompt_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdatePromptTokens() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldPromptTokens)
	return u
}

// AddPromptTokens adds v to the "prompt_tokens" field.
func (u *UsageDetailUpsert) AddPromptTokens(v uint64) *UsageDetailUpsert {
	u.Add(usagedetail.FieldPromptTokens, v)
	return u
}

// ClearPromptTokens clears the value of the "prompt_tokens" field.
func (u *UsageDetailUpsert) ClearPromptTokens() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldPromptTokens)
	return u
}

// SetCompletionTokens sets the "completion_tokens" field.
func (u *UsageDetailUpsert) SetCompletionTokens(v uint64) *UsageDetailUpsert {
	u.Set(usagedetail.FieldCompletionTokens, v)
	return u
}

// UpdateCompletionTokens sets the "completion_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateCompletionTokens() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldCompletionTokens)
	return u
}

// AddCompletionTokens adds v to the "completion_tokens" field.
func (u *UsageDetailUpsert) AddCompletionTokens(v uint64) *UsageDetailUpsert {
	u.Add(usagedetail.FieldCompletionTokens, v)
	return u
}

// ClearCompletionTokens clears the value of the "completion_tokens" field.
func (u *UsageDetailUpsert) ClearCompletionTokens() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldCompletionTokens)
	return u
}

// SetOrganizationID sets the "organization_id" field.
func (u *UsageDetailUpsert) SetOrganizationID(v uint64) *UsageDetailUpsert {
	u.Set(usagedetail.FieldOrganizationID, v)
	return u
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *UsageDetailUpsert) UpdateOrganizationID() *UsageDetailUpsert {
	u.SetExcluded(usagedetail.FieldOrganizationID)
	return u
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *UsageDetailUpsert) AddOrganizationID(v uint64) *UsageDetailUpsert {
	u.Add(usagedetail.FieldOrganizationID, v)
	return u
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *UsageDetailUpsert) ClearOrganizationID() *UsageDetailUpsert {
	u.SetNull(usagedetail.FieldOrganizationID)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.UsageDetail.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(usagedetail.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UsageDetailUpsertOne) UpdateNewValues() *UsageDetailUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(usagedetail.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(usagedetail.FieldCreatedAt)
		}
	}))
	return u
}

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

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

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

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

// SetStatus sets the "status" field.
func (u *UsageDetailUpsertOne) SetStatus(v uint8) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *UsageDetailUpsertOne) AddStatus(v uint8) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddStatus(v)
	})
}

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

// ClearStatus clears the value of the "status" field.
func (u *UsageDetailUpsertOne) ClearStatus() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearStatus()
	})
}

// SetType sets the "type" field.
func (u *UsageDetailUpsertOne) SetType(v int) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetType(v)
	})
}

// AddType adds v to the "type" field.
func (u *UsageDetailUpsertOne) AddType(v int) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddType(v)
	})
}

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

// ClearType clears the value of the "type" field.
func (u *UsageDetailUpsertOne) ClearType() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearType()
	})
}

// SetBotID sets the "bot_id" field.
func (u *UsageDetailUpsertOne) SetBotID(v string) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetBotID(v)
	})
}

// UpdateBotID sets the "bot_id" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateBotID() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateBotID()
	})
}

// SetReceiverID sets the "receiver_id" field.
func (u *UsageDetailUpsertOne) SetReceiverID(v string) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetReceiverID(v)
	})
}

// UpdateReceiverID sets the "receiver_id" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateReceiverID() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateReceiverID()
	})
}

// SetApp sets the "app" field.
func (u *UsageDetailUpsertOne) SetApp(v int) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetApp(v)
	})
}

// AddApp adds v to the "app" field.
func (u *UsageDetailUpsertOne) AddApp(v int) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddApp(v)
	})
}

// UpdateApp sets the "app" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateApp() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateApp()
	})
}

// ClearApp clears the value of the "app" field.
func (u *UsageDetailUpsertOne) ClearApp() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearApp()
	})
}

// SetSessionID sets the "session_id" field.
func (u *UsageDetailUpsertOne) SetSessionID(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetSessionID(v)
	})
}

// AddSessionID adds v to the "session_id" field.
func (u *UsageDetailUpsertOne) AddSessionID(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddSessionID(v)
	})
}

// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateSessionID() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateSessionID()
	})
}

// ClearSessionID clears the value of the "session_id" field.
func (u *UsageDetailUpsertOne) ClearSessionID() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearSessionID()
	})
}

// SetRequest sets the "request" field.
func (u *UsageDetailUpsertOne) SetRequest(v string) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetRequest(v)
	})
}

// UpdateRequest sets the "request" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateRequest() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateRequest()
	})
}

// SetResponse sets the "response" field.
func (u *UsageDetailUpsertOne) SetResponse(v string) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetResponse(v)
	})
}

// UpdateResponse sets the "response" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateResponse() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateResponse()
	})
}

// SetOriginalData sets the "original_data" field.
func (u *UsageDetailUpsertOne) SetOriginalData(v custom_types.OriginalData) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetOriginalData(v)
	})
}

// UpdateOriginalData sets the "original_data" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateOriginalData() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateOriginalData()
	})
}

// SetTotalTokens sets the "total_tokens" field.
func (u *UsageDetailUpsertOne) SetTotalTokens(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetTotalTokens(v)
	})
}

// AddTotalTokens adds v to the "total_tokens" field.
func (u *UsageDetailUpsertOne) AddTotalTokens(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddTotalTokens(v)
	})
}

// UpdateTotalTokens sets the "total_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateTotalTokens() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateTotalTokens()
	})
}

// ClearTotalTokens clears the value of the "total_tokens" field.
func (u *UsageDetailUpsertOne) ClearTotalTokens() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearTotalTokens()
	})
}

// SetPromptTokens sets the "prompt_tokens" field.
func (u *UsageDetailUpsertOne) SetPromptTokens(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetPromptTokens(v)
	})
}

// AddPromptTokens adds v to the "prompt_tokens" field.
func (u *UsageDetailUpsertOne) AddPromptTokens(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddPromptTokens(v)
	})
}

// UpdatePromptTokens sets the "prompt_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdatePromptTokens() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdatePromptTokens()
	})
}

// ClearPromptTokens clears the value of the "prompt_tokens" field.
func (u *UsageDetailUpsertOne) ClearPromptTokens() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearPromptTokens()
	})
}

// SetCompletionTokens sets the "completion_tokens" field.
func (u *UsageDetailUpsertOne) SetCompletionTokens(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetCompletionTokens(v)
	})
}

// AddCompletionTokens adds v to the "completion_tokens" field.
func (u *UsageDetailUpsertOne) AddCompletionTokens(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddCompletionTokens(v)
	})
}

// UpdateCompletionTokens sets the "completion_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateCompletionTokens() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateCompletionTokens()
	})
}

// ClearCompletionTokens clears the value of the "completion_tokens" field.
func (u *UsageDetailUpsertOne) ClearCompletionTokens() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearCompletionTokens()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *UsageDetailUpsertOne) SetOrganizationID(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *UsageDetailUpsertOne) AddOrganizationID(v uint64) *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *UsageDetailUpsertOne) UpdateOrganizationID() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *UsageDetailUpsertOne) ClearOrganizationID() *UsageDetailUpsertOne {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearOrganizationID()
	})
}

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

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

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

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

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

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

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

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

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

// UsageDetailUpsertBulk is the builder for "upsert"-ing
// a bulk of UsageDetail nodes.
type UsageDetailUpsertBulk struct {
	create *UsageDetailCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.UsageDetail.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(usagedetail.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UsageDetailUpsertBulk) UpdateNewValues() *UsageDetailUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(usagedetail.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(usagedetail.FieldCreatedAt)
			}
		}
	}))
	return u
}

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

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

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

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

// SetStatus sets the "status" field.
func (u *UsageDetailUpsertBulk) SetStatus(v uint8) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *UsageDetailUpsertBulk) AddStatus(v uint8) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddStatus(v)
	})
}

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

// ClearStatus clears the value of the "status" field.
func (u *UsageDetailUpsertBulk) ClearStatus() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearStatus()
	})
}

// SetType sets the "type" field.
func (u *UsageDetailUpsertBulk) SetType(v int) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetType(v)
	})
}

// AddType adds v to the "type" field.
func (u *UsageDetailUpsertBulk) AddType(v int) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddType(v)
	})
}

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

// ClearType clears the value of the "type" field.
func (u *UsageDetailUpsertBulk) ClearType() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearType()
	})
}

// SetBotID sets the "bot_id" field.
func (u *UsageDetailUpsertBulk) SetBotID(v string) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetBotID(v)
	})
}

// UpdateBotID sets the "bot_id" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateBotID() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateBotID()
	})
}

// SetReceiverID sets the "receiver_id" field.
func (u *UsageDetailUpsertBulk) SetReceiverID(v string) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetReceiverID(v)
	})
}

// UpdateReceiverID sets the "receiver_id" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateReceiverID() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateReceiverID()
	})
}

// SetApp sets the "app" field.
func (u *UsageDetailUpsertBulk) SetApp(v int) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetApp(v)
	})
}

// AddApp adds v to the "app" field.
func (u *UsageDetailUpsertBulk) AddApp(v int) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddApp(v)
	})
}

// UpdateApp sets the "app" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateApp() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateApp()
	})
}

// ClearApp clears the value of the "app" field.
func (u *UsageDetailUpsertBulk) ClearApp() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearApp()
	})
}

// SetSessionID sets the "session_id" field.
func (u *UsageDetailUpsertBulk) SetSessionID(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetSessionID(v)
	})
}

// AddSessionID adds v to the "session_id" field.
func (u *UsageDetailUpsertBulk) AddSessionID(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddSessionID(v)
	})
}

// UpdateSessionID sets the "session_id" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateSessionID() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateSessionID()
	})
}

// ClearSessionID clears the value of the "session_id" field.
func (u *UsageDetailUpsertBulk) ClearSessionID() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearSessionID()
	})
}

// SetRequest sets the "request" field.
func (u *UsageDetailUpsertBulk) SetRequest(v string) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetRequest(v)
	})
}

// UpdateRequest sets the "request" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateRequest() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateRequest()
	})
}

// SetResponse sets the "response" field.
func (u *UsageDetailUpsertBulk) SetResponse(v string) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetResponse(v)
	})
}

// UpdateResponse sets the "response" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateResponse() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateResponse()
	})
}

// SetOriginalData sets the "original_data" field.
func (u *UsageDetailUpsertBulk) SetOriginalData(v custom_types.OriginalData) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetOriginalData(v)
	})
}

// UpdateOriginalData sets the "original_data" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateOriginalData() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateOriginalData()
	})
}

// SetTotalTokens sets the "total_tokens" field.
func (u *UsageDetailUpsertBulk) SetTotalTokens(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetTotalTokens(v)
	})
}

// AddTotalTokens adds v to the "total_tokens" field.
func (u *UsageDetailUpsertBulk) AddTotalTokens(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddTotalTokens(v)
	})
}

// UpdateTotalTokens sets the "total_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateTotalTokens() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateTotalTokens()
	})
}

// ClearTotalTokens clears the value of the "total_tokens" field.
func (u *UsageDetailUpsertBulk) ClearTotalTokens() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearTotalTokens()
	})
}

// SetPromptTokens sets the "prompt_tokens" field.
func (u *UsageDetailUpsertBulk) SetPromptTokens(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetPromptTokens(v)
	})
}

// AddPromptTokens adds v to the "prompt_tokens" field.
func (u *UsageDetailUpsertBulk) AddPromptTokens(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddPromptTokens(v)
	})
}

// UpdatePromptTokens sets the "prompt_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdatePromptTokens() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdatePromptTokens()
	})
}

// ClearPromptTokens clears the value of the "prompt_tokens" field.
func (u *UsageDetailUpsertBulk) ClearPromptTokens() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearPromptTokens()
	})
}

// SetCompletionTokens sets the "completion_tokens" field.
func (u *UsageDetailUpsertBulk) SetCompletionTokens(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetCompletionTokens(v)
	})
}

// AddCompletionTokens adds v to the "completion_tokens" field.
func (u *UsageDetailUpsertBulk) AddCompletionTokens(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddCompletionTokens(v)
	})
}

// UpdateCompletionTokens sets the "completion_tokens" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateCompletionTokens() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateCompletionTokens()
	})
}

// ClearCompletionTokens clears the value of the "completion_tokens" field.
func (u *UsageDetailUpsertBulk) ClearCompletionTokens() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearCompletionTokens()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *UsageDetailUpsertBulk) SetOrganizationID(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *UsageDetailUpsertBulk) AddOrganizationID(v uint64) *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *UsageDetailUpsertBulk) UpdateOrganizationID() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *UsageDetailUpsertBulk) ClearOrganizationID() *UsageDetailUpsertBulk {
	return u.Update(func(s *UsageDetailUpsert) {
		s.ClearOrganizationID()
	})
}

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

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