// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageStatisticDayUpdate is the builder for updating UsageStatisticDay entities.
type UsageStatisticDayUpdate struct {
	config
	hooks    []Hook
	mutation *UsageStatisticDayMutation
}

// Where appends a list predicates to the UsageStatisticDayUpdate builder.
func (usdu *UsageStatisticDayUpdate) Where(ps ...predicate.UsageStatisticDay) *UsageStatisticDayUpdate {
	usdu.mutation.Where(ps...)
	return usdu
}

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

// SetStatus sets the "status" field.
func (usdu *UsageStatisticDayUpdate) SetStatus(u uint8) *UsageStatisticDayUpdate {
	usdu.mutation.ResetStatus()
	usdu.mutation.SetStatus(u)
	return usdu
}

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

// AddStatus adds u to the "status" field.
func (usdu *UsageStatisticDayUpdate) AddStatus(u int8) *UsageStatisticDayUpdate {
	usdu.mutation.AddStatus(u)
	return usdu
}

// ClearStatus clears the value of the "status" field.
func (usdu *UsageStatisticDayUpdate) ClearStatus() *UsageStatisticDayUpdate {
	usdu.mutation.ClearStatus()
	return usdu
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (usdu *UsageStatisticDayUpdate) ClearDeletedAt() *UsageStatisticDayUpdate {
	usdu.mutation.ClearDeletedAt()
	return usdu
}

// SetAddtime sets the "addtime" field.
func (usdu *UsageStatisticDayUpdate) SetAddtime(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetAddtime()
	usdu.mutation.SetAddtime(u)
	return usdu
}

// SetNillableAddtime sets the "addtime" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableAddtime(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetAddtime(*u)
	}
	return usdu
}

// AddAddtime adds u to the "addtime" field.
func (usdu *UsageStatisticDayUpdate) AddAddtime(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddAddtime(u)
	return usdu
}

// SetType sets the "type" field.
func (usdu *UsageStatisticDayUpdate) SetType(i int) *UsageStatisticDayUpdate {
	usdu.mutation.ResetType()
	usdu.mutation.SetType(i)
	return usdu
}

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

// AddType adds i to the "type" field.
func (usdu *UsageStatisticDayUpdate) AddType(i int) *UsageStatisticDayUpdate {
	usdu.mutation.AddType(i)
	return usdu
}

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

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

// ClearBotID clears the value of the "bot_id" field.
func (usdu *UsageStatisticDayUpdate) ClearBotID() *UsageStatisticDayUpdate {
	usdu.mutation.ClearBotID()
	return usdu
}

// SetOrganizationID sets the "organization_id" field.
func (usdu *UsageStatisticDayUpdate) SetOrganizationID(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetOrganizationID()
	usdu.mutation.SetOrganizationID(u)
	return usdu
}

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

// AddOrganizationID adds u to the "organization_id" field.
func (usdu *UsageStatisticDayUpdate) AddOrganizationID(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddOrganizationID(u)
	return usdu
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (usdu *UsageStatisticDayUpdate) ClearOrganizationID() *UsageStatisticDayUpdate {
	usdu.mutation.ClearOrganizationID()
	return usdu
}

// SetAiResponse sets the "ai_response" field.
func (usdu *UsageStatisticDayUpdate) SetAiResponse(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetAiResponse()
	usdu.mutation.SetAiResponse(u)
	return usdu
}

// SetNillableAiResponse sets the "ai_response" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableAiResponse(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetAiResponse(*u)
	}
	return usdu
}

// AddAiResponse adds u to the "ai_response" field.
func (usdu *UsageStatisticDayUpdate) AddAiResponse(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddAiResponse(u)
	return usdu
}

// SetSopRun sets the "sop_run" field.
func (usdu *UsageStatisticDayUpdate) SetSopRun(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetSopRun()
	usdu.mutation.SetSopRun(u)
	return usdu
}

// SetNillableSopRun sets the "sop_run" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableSopRun(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetSopRun(*u)
	}
	return usdu
}

// AddSopRun adds u to the "sop_run" field.
func (usdu *UsageStatisticDayUpdate) AddSopRun(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddSopRun(u)
	return usdu
}

// SetTotalFriend sets the "total_friend" field.
func (usdu *UsageStatisticDayUpdate) SetTotalFriend(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetTotalFriend()
	usdu.mutation.SetTotalFriend(u)
	return usdu
}

// SetNillableTotalFriend sets the "total_friend" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableTotalFriend(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetTotalFriend(*u)
	}
	return usdu
}

// AddTotalFriend adds u to the "total_friend" field.
func (usdu *UsageStatisticDayUpdate) AddTotalFriend(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddTotalFriend(u)
	return usdu
}

// SetTotalGroup sets the "total_group" field.
func (usdu *UsageStatisticDayUpdate) SetTotalGroup(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetTotalGroup()
	usdu.mutation.SetTotalGroup(u)
	return usdu
}

// SetNillableTotalGroup sets the "total_group" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableTotalGroup(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetTotalGroup(*u)
	}
	return usdu
}

// AddTotalGroup adds u to the "total_group" field.
func (usdu *UsageStatisticDayUpdate) AddTotalGroup(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddTotalGroup(u)
	return usdu
}

// SetAccountBalance sets the "account_balance" field.
func (usdu *UsageStatisticDayUpdate) SetAccountBalance(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetAccountBalance()
	usdu.mutation.SetAccountBalance(u)
	return usdu
}

// SetNillableAccountBalance sets the "account_balance" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableAccountBalance(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetAccountBalance(*u)
	}
	return usdu
}

// AddAccountBalance adds u to the "account_balance" field.
func (usdu *UsageStatisticDayUpdate) AddAccountBalance(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddAccountBalance(u)
	return usdu
}

// SetConsumeToken sets the "consume_token" field.
func (usdu *UsageStatisticDayUpdate) SetConsumeToken(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetConsumeToken()
	usdu.mutation.SetConsumeToken(u)
	return usdu
}

// SetNillableConsumeToken sets the "consume_token" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableConsumeToken(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetConsumeToken(*u)
	}
	return usdu
}

// AddConsumeToken adds u to the "consume_token" field.
func (usdu *UsageStatisticDayUpdate) AddConsumeToken(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddConsumeToken(u)
	return usdu
}

// SetActiveUser sets the "active_user" field.
func (usdu *UsageStatisticDayUpdate) SetActiveUser(u uint64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetActiveUser()
	usdu.mutation.SetActiveUser(u)
	return usdu
}

// SetNillableActiveUser sets the "active_user" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableActiveUser(u *uint64) *UsageStatisticDayUpdate {
	if u != nil {
		usdu.SetActiveUser(*u)
	}
	return usdu
}

// AddActiveUser adds u to the "active_user" field.
func (usdu *UsageStatisticDayUpdate) AddActiveUser(u int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddActiveUser(u)
	return usdu
}

// SetNewUser sets the "new_user" field.
func (usdu *UsageStatisticDayUpdate) SetNewUser(i int64) *UsageStatisticDayUpdate {
	usdu.mutation.ResetNewUser()
	usdu.mutation.SetNewUser(i)
	return usdu
}

// SetNillableNewUser sets the "new_user" field if the given value is not nil.
func (usdu *UsageStatisticDayUpdate) SetNillableNewUser(i *int64) *UsageStatisticDayUpdate {
	if i != nil {
		usdu.SetNewUser(*i)
	}
	return usdu
}

// AddNewUser adds i to the "new_user" field.
func (usdu *UsageStatisticDayUpdate) AddNewUser(i int64) *UsageStatisticDayUpdate {
	usdu.mutation.AddNewUser(i)
	return usdu
}

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

// AppendLabelDist appends ctd to the "label_dist" field.
func (usdu *UsageStatisticDayUpdate) AppendLabelDist(ctd []custom_types.LabelDist) *UsageStatisticDayUpdate {
	usdu.mutation.AppendLabelDist(ctd)
	return usdu
}

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

// Save executes the query and returns the number of nodes affected by the update operation.
func (usdu *UsageStatisticDayUpdate) Save(ctx context.Context) (int, error) {
	if err := usdu.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, usdu.sqlSave, usdu.mutation, usdu.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (usdu *UsageStatisticDayUpdate) defaults() error {
	if _, ok := usdu.mutation.UpdatedAt(); !ok {
		if usagestatisticday.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized usagestatisticday.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := usagestatisticday.UpdateDefaultUpdatedAt()
		usdu.mutation.SetUpdatedAt(v)
	}
	return nil
}

func (usdu *UsageStatisticDayUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(usagestatisticday.Table, usagestatisticday.Columns, sqlgraph.NewFieldSpec(usagestatisticday.FieldID, field.TypeUint64))
	if ps := usdu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := usdu.mutation.UpdatedAt(); ok {
		_spec.SetField(usagestatisticday.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := usdu.mutation.Status(); ok {
		_spec.SetField(usagestatisticday.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := usdu.mutation.AddedStatus(); ok {
		_spec.AddField(usagestatisticday.FieldStatus, field.TypeUint8, value)
	}
	if usdu.mutation.StatusCleared() {
		_spec.ClearField(usagestatisticday.FieldStatus, field.TypeUint8)
	}
	if value, ok := usdu.mutation.DeletedAt(); ok {
		_spec.SetField(usagestatisticday.FieldDeletedAt, field.TypeTime, value)
	}
	if usdu.mutation.DeletedAtCleared() {
		_spec.ClearField(usagestatisticday.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := usdu.mutation.Addtime(); ok {
		_spec.SetField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedAddtime(); ok {
		_spec.AddField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.GetType(); ok {
		_spec.SetField(usagestatisticday.FieldType, field.TypeInt, value)
	}
	if value, ok := usdu.mutation.AddedType(); ok {
		_spec.AddField(usagestatisticday.FieldType, field.TypeInt, value)
	}
	if value, ok := usdu.mutation.BotID(); ok {
		_spec.SetField(usagestatisticday.FieldBotID, field.TypeString, value)
	}
	if usdu.mutation.BotIDCleared() {
		_spec.ClearField(usagestatisticday.FieldBotID, field.TypeString)
	}
	if value, ok := usdu.mutation.OrganizationID(); ok {
		_spec.SetField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedOrganizationID(); ok {
		_spec.AddField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
	}
	if usdu.mutation.OrganizationIDCleared() {
		_spec.ClearField(usagestatisticday.FieldOrganizationID, field.TypeUint64)
	}
	if value, ok := usdu.mutation.AiResponse(); ok {
		_spec.SetField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedAiResponse(); ok {
		_spec.AddField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.SopRun(); ok {
		_spec.SetField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedSopRun(); ok {
		_spec.AddField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.TotalFriend(); ok {
		_spec.SetField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedTotalFriend(); ok {
		_spec.AddField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.TotalGroup(); ok {
		_spec.SetField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedTotalGroup(); ok {
		_spec.AddField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AccountBalance(); ok {
		_spec.SetField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedAccountBalance(); ok {
		_spec.AddField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.ConsumeToken(); ok {
		_spec.SetField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedConsumeToken(); ok {
		_spec.AddField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.ActiveUser(); ok {
		_spec.SetField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.AddedActiveUser(); ok {
		_spec.AddField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
	}
	if value, ok := usdu.mutation.NewUser(); ok {
		_spec.SetField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
	}
	if value, ok := usdu.mutation.AddedNewUser(); ok {
		_spec.AddField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
	}
	if value, ok := usdu.mutation.LabelDist(); ok {
		_spec.SetField(usagestatisticday.FieldLabelDist, field.TypeJSON, value)
	}
	if value, ok := usdu.mutation.AppendedLabelDist(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, usagestatisticday.FieldLabelDist, value)
		})
	}
	if n, err = sqlgraph.UpdateNodes(ctx, usdu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usagestatisticday.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	usdu.mutation.done = true
	return n, nil
}

// UsageStatisticDayUpdateOne is the builder for updating a single UsageStatisticDay entity.
type UsageStatisticDayUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UsageStatisticDayMutation
}

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

// SetStatus sets the "status" field.
func (usduo *UsageStatisticDayUpdateOne) SetStatus(u uint8) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetStatus()
	usduo.mutation.SetStatus(u)
	return usduo
}

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

// AddStatus adds u to the "status" field.
func (usduo *UsageStatisticDayUpdateOne) AddStatus(u int8) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddStatus(u)
	return usduo
}

// ClearStatus clears the value of the "status" field.
func (usduo *UsageStatisticDayUpdateOne) ClearStatus() *UsageStatisticDayUpdateOne {
	usduo.mutation.ClearStatus()
	return usduo
}

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

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

// ClearDeletedAt clears the value of the "deleted_at" field.
func (usduo *UsageStatisticDayUpdateOne) ClearDeletedAt() *UsageStatisticDayUpdateOne {
	usduo.mutation.ClearDeletedAt()
	return usduo
}

// SetAddtime sets the "addtime" field.
func (usduo *UsageStatisticDayUpdateOne) SetAddtime(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetAddtime()
	usduo.mutation.SetAddtime(u)
	return usduo
}

// SetNillableAddtime sets the "addtime" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableAddtime(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetAddtime(*u)
	}
	return usduo
}

// AddAddtime adds u to the "addtime" field.
func (usduo *UsageStatisticDayUpdateOne) AddAddtime(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddAddtime(u)
	return usduo
}

// SetType sets the "type" field.
func (usduo *UsageStatisticDayUpdateOne) SetType(i int) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetType()
	usduo.mutation.SetType(i)
	return usduo
}

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

// AddType adds i to the "type" field.
func (usduo *UsageStatisticDayUpdateOne) AddType(i int) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddType(i)
	return usduo
}

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

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

// ClearBotID clears the value of the "bot_id" field.
func (usduo *UsageStatisticDayUpdateOne) ClearBotID() *UsageStatisticDayUpdateOne {
	usduo.mutation.ClearBotID()
	return usduo
}

// SetOrganizationID sets the "organization_id" field.
func (usduo *UsageStatisticDayUpdateOne) SetOrganizationID(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetOrganizationID()
	usduo.mutation.SetOrganizationID(u)
	return usduo
}

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

// AddOrganizationID adds u to the "organization_id" field.
func (usduo *UsageStatisticDayUpdateOne) AddOrganizationID(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddOrganizationID(u)
	return usduo
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (usduo *UsageStatisticDayUpdateOne) ClearOrganizationID() *UsageStatisticDayUpdateOne {
	usduo.mutation.ClearOrganizationID()
	return usduo
}

// SetAiResponse sets the "ai_response" field.
func (usduo *UsageStatisticDayUpdateOne) SetAiResponse(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetAiResponse()
	usduo.mutation.SetAiResponse(u)
	return usduo
}

// SetNillableAiResponse sets the "ai_response" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableAiResponse(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetAiResponse(*u)
	}
	return usduo
}

// AddAiResponse adds u to the "ai_response" field.
func (usduo *UsageStatisticDayUpdateOne) AddAiResponse(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddAiResponse(u)
	return usduo
}

// SetSopRun sets the "sop_run" field.
func (usduo *UsageStatisticDayUpdateOne) SetSopRun(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetSopRun()
	usduo.mutation.SetSopRun(u)
	return usduo
}

// SetNillableSopRun sets the "sop_run" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableSopRun(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetSopRun(*u)
	}
	return usduo
}

// AddSopRun adds u to the "sop_run" field.
func (usduo *UsageStatisticDayUpdateOne) AddSopRun(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddSopRun(u)
	return usduo
}

// SetTotalFriend sets the "total_friend" field.
func (usduo *UsageStatisticDayUpdateOne) SetTotalFriend(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetTotalFriend()
	usduo.mutation.SetTotalFriend(u)
	return usduo
}

// SetNillableTotalFriend sets the "total_friend" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableTotalFriend(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetTotalFriend(*u)
	}
	return usduo
}

// AddTotalFriend adds u to the "total_friend" field.
func (usduo *UsageStatisticDayUpdateOne) AddTotalFriend(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddTotalFriend(u)
	return usduo
}

// SetTotalGroup sets the "total_group" field.
func (usduo *UsageStatisticDayUpdateOne) SetTotalGroup(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetTotalGroup()
	usduo.mutation.SetTotalGroup(u)
	return usduo
}

// SetNillableTotalGroup sets the "total_group" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableTotalGroup(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetTotalGroup(*u)
	}
	return usduo
}

// AddTotalGroup adds u to the "total_group" field.
func (usduo *UsageStatisticDayUpdateOne) AddTotalGroup(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddTotalGroup(u)
	return usduo
}

// SetAccountBalance sets the "account_balance" field.
func (usduo *UsageStatisticDayUpdateOne) SetAccountBalance(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetAccountBalance()
	usduo.mutation.SetAccountBalance(u)
	return usduo
}

// SetNillableAccountBalance sets the "account_balance" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableAccountBalance(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetAccountBalance(*u)
	}
	return usduo
}

// AddAccountBalance adds u to the "account_balance" field.
func (usduo *UsageStatisticDayUpdateOne) AddAccountBalance(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddAccountBalance(u)
	return usduo
}

// SetConsumeToken sets the "consume_token" field.
func (usduo *UsageStatisticDayUpdateOne) SetConsumeToken(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetConsumeToken()
	usduo.mutation.SetConsumeToken(u)
	return usduo
}

// SetNillableConsumeToken sets the "consume_token" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableConsumeToken(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetConsumeToken(*u)
	}
	return usduo
}

// AddConsumeToken adds u to the "consume_token" field.
func (usduo *UsageStatisticDayUpdateOne) AddConsumeToken(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddConsumeToken(u)
	return usduo
}

// SetActiveUser sets the "active_user" field.
func (usduo *UsageStatisticDayUpdateOne) SetActiveUser(u uint64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetActiveUser()
	usduo.mutation.SetActiveUser(u)
	return usduo
}

// SetNillableActiveUser sets the "active_user" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableActiveUser(u *uint64) *UsageStatisticDayUpdateOne {
	if u != nil {
		usduo.SetActiveUser(*u)
	}
	return usduo
}

// AddActiveUser adds u to the "active_user" field.
func (usduo *UsageStatisticDayUpdateOne) AddActiveUser(u int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddActiveUser(u)
	return usduo
}

// SetNewUser sets the "new_user" field.
func (usduo *UsageStatisticDayUpdateOne) SetNewUser(i int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.ResetNewUser()
	usduo.mutation.SetNewUser(i)
	return usduo
}

// SetNillableNewUser sets the "new_user" field if the given value is not nil.
func (usduo *UsageStatisticDayUpdateOne) SetNillableNewUser(i *int64) *UsageStatisticDayUpdateOne {
	if i != nil {
		usduo.SetNewUser(*i)
	}
	return usduo
}

// AddNewUser adds i to the "new_user" field.
func (usduo *UsageStatisticDayUpdateOne) AddNewUser(i int64) *UsageStatisticDayUpdateOne {
	usduo.mutation.AddNewUser(i)
	return usduo
}

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

// AppendLabelDist appends ctd to the "label_dist" field.
func (usduo *UsageStatisticDayUpdateOne) AppendLabelDist(ctd []custom_types.LabelDist) *UsageStatisticDayUpdateOne {
	usduo.mutation.AppendLabelDist(ctd)
	return usduo
}

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

// Where appends a list predicates to the UsageStatisticDayUpdate builder.
func (usduo *UsageStatisticDayUpdateOne) Where(ps ...predicate.UsageStatisticDay) *UsageStatisticDayUpdateOne {
	usduo.mutation.Where(ps...)
	return usduo
}

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

// Save executes the query and returns the updated UsageStatisticDay entity.
func (usduo *UsageStatisticDayUpdateOne) Save(ctx context.Context) (*UsageStatisticDay, error) {
	if err := usduo.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, usduo.sqlSave, usduo.mutation, usduo.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (usduo *UsageStatisticDayUpdateOne) defaults() error {
	if _, ok := usduo.mutation.UpdatedAt(); !ok {
		if usagestatisticday.UpdateDefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized usagestatisticday.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := usagestatisticday.UpdateDefaultUpdatedAt()
		usduo.mutation.SetUpdatedAt(v)
	}
	return nil
}

func (usduo *UsageStatisticDayUpdateOne) sqlSave(ctx context.Context) (_node *UsageStatisticDay, err error) {
	_spec := sqlgraph.NewUpdateSpec(usagestatisticday.Table, usagestatisticday.Columns, sqlgraph.NewFieldSpec(usagestatisticday.FieldID, field.TypeUint64))
	id, ok := usduo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageStatisticDay.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := usduo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, usagestatisticday.FieldID)
		for _, f := range fields {
			if !usagestatisticday.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != usagestatisticday.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := usduo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := usduo.mutation.UpdatedAt(); ok {
		_spec.SetField(usagestatisticday.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := usduo.mutation.Status(); ok {
		_spec.SetField(usagestatisticday.FieldStatus, field.TypeUint8, value)
	}
	if value, ok := usduo.mutation.AddedStatus(); ok {
		_spec.AddField(usagestatisticday.FieldStatus, field.TypeUint8, value)
	}
	if usduo.mutation.StatusCleared() {
		_spec.ClearField(usagestatisticday.FieldStatus, field.TypeUint8)
	}
	if value, ok := usduo.mutation.DeletedAt(); ok {
		_spec.SetField(usagestatisticday.FieldDeletedAt, field.TypeTime, value)
	}
	if usduo.mutation.DeletedAtCleared() {
		_spec.ClearField(usagestatisticday.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := usduo.mutation.Addtime(); ok {
		_spec.SetField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedAddtime(); ok {
		_spec.AddField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.GetType(); ok {
		_spec.SetField(usagestatisticday.FieldType, field.TypeInt, value)
	}
	if value, ok := usduo.mutation.AddedType(); ok {
		_spec.AddField(usagestatisticday.FieldType, field.TypeInt, value)
	}
	if value, ok := usduo.mutation.BotID(); ok {
		_spec.SetField(usagestatisticday.FieldBotID, field.TypeString, value)
	}
	if usduo.mutation.BotIDCleared() {
		_spec.ClearField(usagestatisticday.FieldBotID, field.TypeString)
	}
	if value, ok := usduo.mutation.OrganizationID(); ok {
		_spec.SetField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedOrganizationID(); ok {
		_spec.AddField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
	}
	if usduo.mutation.OrganizationIDCleared() {
		_spec.ClearField(usagestatisticday.FieldOrganizationID, field.TypeUint64)
	}
	if value, ok := usduo.mutation.AiResponse(); ok {
		_spec.SetField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedAiResponse(); ok {
		_spec.AddField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.SopRun(); ok {
		_spec.SetField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedSopRun(); ok {
		_spec.AddField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.TotalFriend(); ok {
		_spec.SetField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedTotalFriend(); ok {
		_spec.AddField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.TotalGroup(); ok {
		_spec.SetField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedTotalGroup(); ok {
		_spec.AddField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AccountBalance(); ok {
		_spec.SetField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedAccountBalance(); ok {
		_spec.AddField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.ConsumeToken(); ok {
		_spec.SetField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedConsumeToken(); ok {
		_spec.AddField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.ActiveUser(); ok {
		_spec.SetField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.AddedActiveUser(); ok {
		_spec.AddField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
	}
	if value, ok := usduo.mutation.NewUser(); ok {
		_spec.SetField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
	}
	if value, ok := usduo.mutation.AddedNewUser(); ok {
		_spec.AddField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
	}
	if value, ok := usduo.mutation.LabelDist(); ok {
		_spec.SetField(usagestatisticday.FieldLabelDist, field.TypeJSON, value)
	}
	if value, ok := usduo.mutation.AppendedLabelDist(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, usagestatisticday.FieldLabelDist, value)
		})
	}
	_node = &UsageStatisticDay{config: usduo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, usduo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usagestatisticday.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	usduo.mutation.done = true
	return _node, nil
}