// 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/usagestatistichour"

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

// UsageStatisticHourUpdate is the builder for updating UsageStatisticHour entities.
type UsageStatisticHourUpdate struct {
	config
	hooks    []Hook
	mutation *UsageStatisticHourMutation
}

// Where appends a list predicates to the UsageStatisticHourUpdate builder.
func (ushu *UsageStatisticHourUpdate) Where(ps ...predicate.UsageStatisticHour) *UsageStatisticHourUpdate {
	ushu.mutation.Where(ps...)
	return ushu
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Mutation returns the UsageStatisticHourMutation object of the builder.
func (ushu *UsageStatisticHourUpdate) Mutation() *UsageStatisticHourMutation {
	return ushu.mutation
}

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

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

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

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

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

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

// UsageStatisticHourUpdateOne is the builder for updating a single UsageStatisticHour entity.
type UsageStatisticHourUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UsageStatisticHourMutation
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Mutation returns the UsageStatisticHourMutation object of the builder.
func (ushuo *UsageStatisticHourUpdateOne) Mutation() *UsageStatisticHourMutation {
	return ushuo.mutation
}

// Where appends a list predicates to the UsageStatisticHourUpdate builder.
func (ushuo *UsageStatisticHourUpdateOne) Where(ps ...predicate.UsageStatisticHour) *UsageStatisticHourUpdateOne {
	ushuo.mutation.Where(ps...)
	return ushuo
}

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

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

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

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

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

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

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