// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageStatisticDayCreate is the builder for creating a UsageStatisticDay entity.
type UsageStatisticDayCreate struct {
	config
	mutation *UsageStatisticDayMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

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

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

// SetDeletedAt sets the "deleted_at" field.
func (usdc *UsageStatisticDayCreate) SetDeletedAt(t time.Time) *UsageStatisticDayCreate {
	usdc.mutation.SetDeletedAt(t)
	return usdc
}

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

// SetAddtime sets the "addtime" field.
func (usdc *UsageStatisticDayCreate) SetAddtime(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetAddtime(u)
	return usdc
}

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

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

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

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

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

// SetAiResponse sets the "ai_response" field.
func (usdc *UsageStatisticDayCreate) SetAiResponse(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetAiResponse(u)
	return usdc
}

// SetSopRun sets the "sop_run" field.
func (usdc *UsageStatisticDayCreate) SetSopRun(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetSopRun(u)
	return usdc
}

// SetTotalFriend sets the "total_friend" field.
func (usdc *UsageStatisticDayCreate) SetTotalFriend(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetTotalFriend(u)
	return usdc
}

// SetTotalGroup sets the "total_group" field.
func (usdc *UsageStatisticDayCreate) SetTotalGroup(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetTotalGroup(u)
	return usdc
}

// SetAccountBalance sets the "account_balance" field.
func (usdc *UsageStatisticDayCreate) SetAccountBalance(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetAccountBalance(u)
	return usdc
}

// SetConsumeToken sets the "consume_token" field.
func (usdc *UsageStatisticDayCreate) SetConsumeToken(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetConsumeToken(u)
	return usdc
}

// SetActiveUser sets the "active_user" field.
func (usdc *UsageStatisticDayCreate) SetActiveUser(u uint64) *UsageStatisticDayCreate {
	usdc.mutation.SetActiveUser(u)
	return usdc
}

// SetNewUser sets the "new_user" field.
func (usdc *UsageStatisticDayCreate) SetNewUser(i int64) *UsageStatisticDayCreate {
	usdc.mutation.SetNewUser(i)
	return usdc
}

// SetLabelDist sets the "label_dist" field.
func (usdc *UsageStatisticDayCreate) SetLabelDist(ctd []custom_types.LabelDist) *UsageStatisticDayCreate {
	usdc.mutation.SetLabelDist(ctd)
	return usdc
}

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

// Mutation returns the UsageStatisticDayMutation object of the builder.
func (usdc *UsageStatisticDayCreate) Mutation() *UsageStatisticDayMutation {
	return usdc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (usdc *UsageStatisticDayCreate) defaults() error {
	if _, ok := usdc.mutation.CreatedAt(); !ok {
		if usagestatisticday.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized usagestatisticday.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := usagestatisticday.DefaultCreatedAt()
		usdc.mutation.SetCreatedAt(v)
	}
	if _, ok := usdc.mutation.UpdatedAt(); !ok {
		if usagestatisticday.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized usagestatisticday.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := usagestatisticday.DefaultUpdatedAt()
		usdc.mutation.SetUpdatedAt(v)
	}
	if _, ok := usdc.mutation.Status(); !ok {
		v := usagestatisticday.DefaultStatus
		usdc.mutation.SetStatus(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (usdc *UsageStatisticDayCreate) check() error {
	if _, ok := usdc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UsageStatisticDay.created_at"`)}
	}
	if _, ok := usdc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UsageStatisticDay.updated_at"`)}
	}
	if _, ok := usdc.mutation.Addtime(); !ok {
		return &ValidationError{Name: "addtime", err: errors.New(`ent: missing required field "UsageStatisticDay.addtime"`)}
	}
	if _, ok := usdc.mutation.GetType(); !ok {
		return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "UsageStatisticDay.type"`)}
	}
	if _, ok := usdc.mutation.AiResponse(); !ok {
		return &ValidationError{Name: "ai_response", err: errors.New(`ent: missing required field "UsageStatisticDay.ai_response"`)}
	}
	if _, ok := usdc.mutation.SopRun(); !ok {
		return &ValidationError{Name: "sop_run", err: errors.New(`ent: missing required field "UsageStatisticDay.sop_run"`)}
	}
	if _, ok := usdc.mutation.TotalFriend(); !ok {
		return &ValidationError{Name: "total_friend", err: errors.New(`ent: missing required field "UsageStatisticDay.total_friend"`)}
	}
	if _, ok := usdc.mutation.TotalGroup(); !ok {
		return &ValidationError{Name: "total_group", err: errors.New(`ent: missing required field "UsageStatisticDay.total_group"`)}
	}
	if _, ok := usdc.mutation.AccountBalance(); !ok {
		return &ValidationError{Name: "account_balance", err: errors.New(`ent: missing required field "UsageStatisticDay.account_balance"`)}
	}
	if _, ok := usdc.mutation.ConsumeToken(); !ok {
		return &ValidationError{Name: "consume_token", err: errors.New(`ent: missing required field "UsageStatisticDay.consume_token"`)}
	}
	if _, ok := usdc.mutation.ActiveUser(); !ok {
		return &ValidationError{Name: "active_user", err: errors.New(`ent: missing required field "UsageStatisticDay.active_user"`)}
	}
	if _, ok := usdc.mutation.NewUser(); !ok {
		return &ValidationError{Name: "new_user", err: errors.New(`ent: missing required field "UsageStatisticDay.new_user"`)}
	}
	if _, ok := usdc.mutation.LabelDist(); !ok {
		return &ValidationError{Name: "label_dist", err: errors.New(`ent: missing required field "UsageStatisticDay.label_dist"`)}
	}
	return nil
}

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

func (usdc *UsageStatisticDayCreate) createSpec() (*UsageStatisticDay, *sqlgraph.CreateSpec) {
	var (
		_node = &UsageStatisticDay{config: usdc.config}
		_spec = sqlgraph.NewCreateSpec(usagestatisticday.Table, sqlgraph.NewFieldSpec(usagestatisticday.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = usdc.conflict
	if id, ok := usdc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := usdc.mutation.CreatedAt(); ok {
		_spec.SetField(usagestatisticday.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := usdc.mutation.UpdatedAt(); ok {
		_spec.SetField(usagestatisticday.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := usdc.mutation.Status(); ok {
		_spec.SetField(usagestatisticday.FieldStatus, field.TypeUint8, value)
		_node.Status = value
	}
	if value, ok := usdc.mutation.DeletedAt(); ok {
		_spec.SetField(usagestatisticday.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := usdc.mutation.Addtime(); ok {
		_spec.SetField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
		_node.Addtime = value
	}
	if value, ok := usdc.mutation.GetType(); ok {
		_spec.SetField(usagestatisticday.FieldType, field.TypeInt, value)
		_node.Type = value
	}
	if value, ok := usdc.mutation.BotID(); ok {
		_spec.SetField(usagestatisticday.FieldBotID, field.TypeString, value)
		_node.BotID = value
	}
	if value, ok := usdc.mutation.OrganizationID(); ok {
		_spec.SetField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
		_node.OrganizationID = value
	}
	if value, ok := usdc.mutation.AiResponse(); ok {
		_spec.SetField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
		_node.AiResponse = value
	}
	if value, ok := usdc.mutation.SopRun(); ok {
		_spec.SetField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
		_node.SopRun = value
	}
	if value, ok := usdc.mutation.TotalFriend(); ok {
		_spec.SetField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
		_node.TotalFriend = value
	}
	if value, ok := usdc.mutation.TotalGroup(); ok {
		_spec.SetField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
		_node.TotalGroup = value
	}
	if value, ok := usdc.mutation.AccountBalance(); ok {
		_spec.SetField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
		_node.AccountBalance = value
	}
	if value, ok := usdc.mutation.ConsumeToken(); ok {
		_spec.SetField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
		_node.ConsumeToken = value
	}
	if value, ok := usdc.mutation.ActiveUser(); ok {
		_spec.SetField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
		_node.ActiveUser = value
	}
	if value, ok := usdc.mutation.NewUser(); ok {
		_spec.SetField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
		_node.NewUser = value
	}
	if value, ok := usdc.mutation.LabelDist(); ok {
		_spec.SetField(usagestatisticday.FieldLabelDist, field.TypeJSON, value)
		_node.LabelDist = value
	}
	return _node, _spec
}

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

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

type (
	// UsageStatisticDayUpsertOne is the builder for "upsert"-ing
	//  one UsageStatisticDay node.
	UsageStatisticDayUpsertOne struct {
		create *UsageStatisticDayCreate
	}

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

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

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

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

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

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

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

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

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

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

// SetAddtime sets the "addtime" field.
func (u *UsageStatisticDayUpsert) SetAddtime(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldAddtime, v)
	return u
}

// UpdateAddtime sets the "addtime" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateAddtime() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldAddtime)
	return u
}

// AddAddtime adds v to the "addtime" field.
func (u *UsageStatisticDayUpsert) AddAddtime(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldAddtime, v)
	return u
}

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

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

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

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

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

// ClearBotID clears the value of the "bot_id" field.
func (u *UsageStatisticDayUpsert) ClearBotID() *UsageStatisticDayUpsert {
	u.SetNull(usagestatisticday.FieldBotID)
	return u
}

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

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

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

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

// SetAiResponse sets the "ai_response" field.
func (u *UsageStatisticDayUpsert) SetAiResponse(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldAiResponse, v)
	return u
}

// UpdateAiResponse sets the "ai_response" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateAiResponse() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldAiResponse)
	return u
}

// AddAiResponse adds v to the "ai_response" field.
func (u *UsageStatisticDayUpsert) AddAiResponse(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldAiResponse, v)
	return u
}

// SetSopRun sets the "sop_run" field.
func (u *UsageStatisticDayUpsert) SetSopRun(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldSopRun, v)
	return u
}

// UpdateSopRun sets the "sop_run" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateSopRun() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldSopRun)
	return u
}

// AddSopRun adds v to the "sop_run" field.
func (u *UsageStatisticDayUpsert) AddSopRun(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldSopRun, v)
	return u
}

// SetTotalFriend sets the "total_friend" field.
func (u *UsageStatisticDayUpsert) SetTotalFriend(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldTotalFriend, v)
	return u
}

// UpdateTotalFriend sets the "total_friend" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateTotalFriend() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldTotalFriend)
	return u
}

// AddTotalFriend adds v to the "total_friend" field.
func (u *UsageStatisticDayUpsert) AddTotalFriend(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldTotalFriend, v)
	return u
}

// SetTotalGroup sets the "total_group" field.
func (u *UsageStatisticDayUpsert) SetTotalGroup(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldTotalGroup, v)
	return u
}

// UpdateTotalGroup sets the "total_group" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateTotalGroup() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldTotalGroup)
	return u
}

// AddTotalGroup adds v to the "total_group" field.
func (u *UsageStatisticDayUpsert) AddTotalGroup(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldTotalGroup, v)
	return u
}

// SetAccountBalance sets the "account_balance" field.
func (u *UsageStatisticDayUpsert) SetAccountBalance(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldAccountBalance, v)
	return u
}

// UpdateAccountBalance sets the "account_balance" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateAccountBalance() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldAccountBalance)
	return u
}

// AddAccountBalance adds v to the "account_balance" field.
func (u *UsageStatisticDayUpsert) AddAccountBalance(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldAccountBalance, v)
	return u
}

// SetConsumeToken sets the "consume_token" field.
func (u *UsageStatisticDayUpsert) SetConsumeToken(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldConsumeToken, v)
	return u
}

// UpdateConsumeToken sets the "consume_token" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateConsumeToken() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldConsumeToken)
	return u
}

// AddConsumeToken adds v to the "consume_token" field.
func (u *UsageStatisticDayUpsert) AddConsumeToken(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldConsumeToken, v)
	return u
}

// SetActiveUser sets the "active_user" field.
func (u *UsageStatisticDayUpsert) SetActiveUser(v uint64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldActiveUser, v)
	return u
}

// UpdateActiveUser sets the "active_user" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateActiveUser() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldActiveUser)
	return u
}

// AddActiveUser adds v to the "active_user" field.
func (u *UsageStatisticDayUpsert) AddActiveUser(v uint64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldActiveUser, v)
	return u
}

// SetNewUser sets the "new_user" field.
func (u *UsageStatisticDayUpsert) SetNewUser(v int64) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldNewUser, v)
	return u
}

// UpdateNewUser sets the "new_user" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateNewUser() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldNewUser)
	return u
}

// AddNewUser adds v to the "new_user" field.
func (u *UsageStatisticDayUpsert) AddNewUser(v int64) *UsageStatisticDayUpsert {
	u.Add(usagestatisticday.FieldNewUser, v)
	return u
}

// SetLabelDist sets the "label_dist" field.
func (u *UsageStatisticDayUpsert) SetLabelDist(v []custom_types.LabelDist) *UsageStatisticDayUpsert {
	u.Set(usagestatisticday.FieldLabelDist, v)
	return u
}

// UpdateLabelDist sets the "label_dist" field to the value that was provided on create.
func (u *UsageStatisticDayUpsert) UpdateLabelDist() *UsageStatisticDayUpsert {
	u.SetExcluded(usagestatisticday.FieldLabelDist)
	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.UsageStatisticDay.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(usagestatisticday.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UsageStatisticDayUpsertOne) UpdateNewValues() *UsageStatisticDayUpsertOne {
	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(usagestatisticday.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(usagestatisticday.FieldCreatedAt)
		}
	}))
	return u
}

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

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

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

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

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

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

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

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

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

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

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

// SetAddtime sets the "addtime" field.
func (u *UsageStatisticDayUpsertOne) SetAddtime(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetAddtime(v)
	})
}

// AddAddtime adds v to the "addtime" field.
func (u *UsageStatisticDayUpsertOne) AddAddtime(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddAddtime(v)
	})
}

// UpdateAddtime sets the "addtime" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateAddtime() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateAddtime()
	})
}

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

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

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

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

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

// ClearBotID clears the value of the "bot_id" field.
func (u *UsageStatisticDayUpsertOne) ClearBotID() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.ClearBotID()
	})
}

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

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

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

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

// SetAiResponse sets the "ai_response" field.
func (u *UsageStatisticDayUpsertOne) SetAiResponse(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetAiResponse(v)
	})
}

// AddAiResponse adds v to the "ai_response" field.
func (u *UsageStatisticDayUpsertOne) AddAiResponse(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddAiResponse(v)
	})
}

// UpdateAiResponse sets the "ai_response" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateAiResponse() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateAiResponse()
	})
}

// SetSopRun sets the "sop_run" field.
func (u *UsageStatisticDayUpsertOne) SetSopRun(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetSopRun(v)
	})
}

// AddSopRun adds v to the "sop_run" field.
func (u *UsageStatisticDayUpsertOne) AddSopRun(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddSopRun(v)
	})
}

// UpdateSopRun sets the "sop_run" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateSopRun() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateSopRun()
	})
}

// SetTotalFriend sets the "total_friend" field.
func (u *UsageStatisticDayUpsertOne) SetTotalFriend(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetTotalFriend(v)
	})
}

// AddTotalFriend adds v to the "total_friend" field.
func (u *UsageStatisticDayUpsertOne) AddTotalFriend(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddTotalFriend(v)
	})
}

// UpdateTotalFriend sets the "total_friend" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateTotalFriend() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateTotalFriend()
	})
}

// SetTotalGroup sets the "total_group" field.
func (u *UsageStatisticDayUpsertOne) SetTotalGroup(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetTotalGroup(v)
	})
}

// AddTotalGroup adds v to the "total_group" field.
func (u *UsageStatisticDayUpsertOne) AddTotalGroup(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddTotalGroup(v)
	})
}

// UpdateTotalGroup sets the "total_group" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateTotalGroup() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateTotalGroup()
	})
}

// SetAccountBalance sets the "account_balance" field.
func (u *UsageStatisticDayUpsertOne) SetAccountBalance(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetAccountBalance(v)
	})
}

// AddAccountBalance adds v to the "account_balance" field.
func (u *UsageStatisticDayUpsertOne) AddAccountBalance(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddAccountBalance(v)
	})
}

// UpdateAccountBalance sets the "account_balance" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateAccountBalance() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateAccountBalance()
	})
}

// SetConsumeToken sets the "consume_token" field.
func (u *UsageStatisticDayUpsertOne) SetConsumeToken(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetConsumeToken(v)
	})
}

// AddConsumeToken adds v to the "consume_token" field.
func (u *UsageStatisticDayUpsertOne) AddConsumeToken(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddConsumeToken(v)
	})
}

// UpdateConsumeToken sets the "consume_token" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateConsumeToken() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateConsumeToken()
	})
}

// SetActiveUser sets the "active_user" field.
func (u *UsageStatisticDayUpsertOne) SetActiveUser(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetActiveUser(v)
	})
}

// AddActiveUser adds v to the "active_user" field.
func (u *UsageStatisticDayUpsertOne) AddActiveUser(v uint64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddActiveUser(v)
	})
}

// UpdateActiveUser sets the "active_user" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateActiveUser() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateActiveUser()
	})
}

// SetNewUser sets the "new_user" field.
func (u *UsageStatisticDayUpsertOne) SetNewUser(v int64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetNewUser(v)
	})
}

// AddNewUser adds v to the "new_user" field.
func (u *UsageStatisticDayUpsertOne) AddNewUser(v int64) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddNewUser(v)
	})
}

// UpdateNewUser sets the "new_user" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateNewUser() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateNewUser()
	})
}

// SetLabelDist sets the "label_dist" field.
func (u *UsageStatisticDayUpsertOne) SetLabelDist(v []custom_types.LabelDist) *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetLabelDist(v)
	})
}

// UpdateLabelDist sets the "label_dist" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertOne) UpdateLabelDist() *UsageStatisticDayUpsertOne {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateLabelDist()
	})
}

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

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

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

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

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

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

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

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

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

// UsageStatisticDayUpsertBulk is the builder for "upsert"-ing
// a bulk of UsageStatisticDay nodes.
type UsageStatisticDayUpsertBulk struct {
	create *UsageStatisticDayCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.UsageStatisticDay.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(usagestatisticday.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UsageStatisticDayUpsertBulk) UpdateNewValues() *UsageStatisticDayUpsertBulk {
	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(usagestatisticday.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(usagestatisticday.FieldCreatedAt)
			}
		}
	}))
	return u
}

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

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

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

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

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

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

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

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

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

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

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

// SetAddtime sets the "addtime" field.
func (u *UsageStatisticDayUpsertBulk) SetAddtime(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetAddtime(v)
	})
}

// AddAddtime adds v to the "addtime" field.
func (u *UsageStatisticDayUpsertBulk) AddAddtime(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddAddtime(v)
	})
}

// UpdateAddtime sets the "addtime" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateAddtime() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateAddtime()
	})
}

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

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

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

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

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

// ClearBotID clears the value of the "bot_id" field.
func (u *UsageStatisticDayUpsertBulk) ClearBotID() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.ClearBotID()
	})
}

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

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

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

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

// SetAiResponse sets the "ai_response" field.
func (u *UsageStatisticDayUpsertBulk) SetAiResponse(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetAiResponse(v)
	})
}

// AddAiResponse adds v to the "ai_response" field.
func (u *UsageStatisticDayUpsertBulk) AddAiResponse(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddAiResponse(v)
	})
}

// UpdateAiResponse sets the "ai_response" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateAiResponse() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateAiResponse()
	})
}

// SetSopRun sets the "sop_run" field.
func (u *UsageStatisticDayUpsertBulk) SetSopRun(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetSopRun(v)
	})
}

// AddSopRun adds v to the "sop_run" field.
func (u *UsageStatisticDayUpsertBulk) AddSopRun(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddSopRun(v)
	})
}

// UpdateSopRun sets the "sop_run" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateSopRun() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateSopRun()
	})
}

// SetTotalFriend sets the "total_friend" field.
func (u *UsageStatisticDayUpsertBulk) SetTotalFriend(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetTotalFriend(v)
	})
}

// AddTotalFriend adds v to the "total_friend" field.
func (u *UsageStatisticDayUpsertBulk) AddTotalFriend(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddTotalFriend(v)
	})
}

// UpdateTotalFriend sets the "total_friend" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateTotalFriend() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateTotalFriend()
	})
}

// SetTotalGroup sets the "total_group" field.
func (u *UsageStatisticDayUpsertBulk) SetTotalGroup(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetTotalGroup(v)
	})
}

// AddTotalGroup adds v to the "total_group" field.
func (u *UsageStatisticDayUpsertBulk) AddTotalGroup(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddTotalGroup(v)
	})
}

// UpdateTotalGroup sets the "total_group" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateTotalGroup() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateTotalGroup()
	})
}

// SetAccountBalance sets the "account_balance" field.
func (u *UsageStatisticDayUpsertBulk) SetAccountBalance(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetAccountBalance(v)
	})
}

// AddAccountBalance adds v to the "account_balance" field.
func (u *UsageStatisticDayUpsertBulk) AddAccountBalance(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddAccountBalance(v)
	})
}

// UpdateAccountBalance sets the "account_balance" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateAccountBalance() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateAccountBalance()
	})
}

// SetConsumeToken sets the "consume_token" field.
func (u *UsageStatisticDayUpsertBulk) SetConsumeToken(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetConsumeToken(v)
	})
}

// AddConsumeToken adds v to the "consume_token" field.
func (u *UsageStatisticDayUpsertBulk) AddConsumeToken(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddConsumeToken(v)
	})
}

// UpdateConsumeToken sets the "consume_token" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateConsumeToken() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateConsumeToken()
	})
}

// SetActiveUser sets the "active_user" field.
func (u *UsageStatisticDayUpsertBulk) SetActiveUser(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetActiveUser(v)
	})
}

// AddActiveUser adds v to the "active_user" field.
func (u *UsageStatisticDayUpsertBulk) AddActiveUser(v uint64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddActiveUser(v)
	})
}

// UpdateActiveUser sets the "active_user" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateActiveUser() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateActiveUser()
	})
}

// SetNewUser sets the "new_user" field.
func (u *UsageStatisticDayUpsertBulk) SetNewUser(v int64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetNewUser(v)
	})
}

// AddNewUser adds v to the "new_user" field.
func (u *UsageStatisticDayUpsertBulk) AddNewUser(v int64) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.AddNewUser(v)
	})
}

// UpdateNewUser sets the "new_user" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateNewUser() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateNewUser()
	})
}

// SetLabelDist sets the "label_dist" field.
func (u *UsageStatisticDayUpsertBulk) SetLabelDist(v []custom_types.LabelDist) *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.SetLabelDist(v)
	})
}

// UpdateLabelDist sets the "label_dist" field to the value that was provided on create.
func (u *UsageStatisticDayUpsertBulk) UpdateLabelDist() *UsageStatisticDayUpsertBulk {
	return u.Update(func(s *UsageStatisticDayUpsert) {
		s.UpdateLabelDist()
	})
}

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

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