// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/Wei-Shaw/sub2api/ent/account"
	"github.com/Wei-Shaw/sub2api/ent/apikey"
	"github.com/Wei-Shaw/sub2api/ent/group"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
	"github.com/Wei-Shaw/sub2api/ent/usagelog"
	"github.com/Wei-Shaw/sub2api/ent/user"
	"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)

// UsageLogUpdate is the builder for updating UsageLog entities.
type UsageLogUpdate struct {
	config
	hooks    []Hook
	mutation *UsageLogMutation
}

// Where appends a list predicates to the UsageLogUpdate builder.
func (_u *UsageLogUpdate) Where(ps ...predicate.UsageLog) *UsageLogUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetUserID sets the "user_id" field.
func (_u *UsageLogUpdate) SetUserID(v int64) *UsageLogUpdate {
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableUserID(v *int64) *UsageLogUpdate {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// SetAPIKeyID sets the "api_key_id" field.
func (_u *UsageLogUpdate) SetAPIKeyID(v int64) *UsageLogUpdate {
	_u.mutation.SetAPIKeyID(v)
	return _u
}

// SetNillableAPIKeyID sets the "api_key_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableAPIKeyID(v *int64) *UsageLogUpdate {
	if v != nil {
		_u.SetAPIKeyID(*v)
	}
	return _u
}

// SetAccountID sets the "account_id" field.
func (_u *UsageLogUpdate) SetAccountID(v int64) *UsageLogUpdate {
	_u.mutation.SetAccountID(v)
	return _u
}

// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableAccountID(v *int64) *UsageLogUpdate {
	if v != nil {
		_u.SetAccountID(*v)
	}
	return _u
}

// SetRequestID sets the "request_id" field.
func (_u *UsageLogUpdate) SetRequestID(v string) *UsageLogUpdate {
	_u.mutation.SetRequestID(v)
	return _u
}

// SetNillableRequestID sets the "request_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableRequestID(v *string) *UsageLogUpdate {
	if v != nil {
		_u.SetRequestID(*v)
	}
	return _u
}

// SetModel sets the "model" field.
func (_u *UsageLogUpdate) SetModel(v string) *UsageLogUpdate {
	_u.mutation.SetModel(v)
	return _u
}

// SetNillableModel sets the "model" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableModel(v *string) *UsageLogUpdate {
	if v != nil {
		_u.SetModel(*v)
	}
	return _u
}

// SetGroupID sets the "group_id" field.
func (_u *UsageLogUpdate) SetGroupID(v int64) *UsageLogUpdate {
	_u.mutation.SetGroupID(v)
	return _u
}

// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableGroupID(v *int64) *UsageLogUpdate {
	if v != nil {
		_u.SetGroupID(*v)
	}
	return _u
}

// ClearGroupID clears the value of the "group_id" field.
func (_u *UsageLogUpdate) ClearGroupID() *UsageLogUpdate {
	_u.mutation.ClearGroupID()
	return _u
}

// SetSubscriptionID sets the "subscription_id" field.
func (_u *UsageLogUpdate) SetSubscriptionID(v int64) *UsageLogUpdate {
	_u.mutation.SetSubscriptionID(v)
	return _u
}

// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableSubscriptionID(v *int64) *UsageLogUpdate {
	if v != nil {
		_u.SetSubscriptionID(*v)
	}
	return _u
}

// ClearSubscriptionID clears the value of the "subscription_id" field.
func (_u *UsageLogUpdate) ClearSubscriptionID() *UsageLogUpdate {
	_u.mutation.ClearSubscriptionID()
	return _u
}

// SetInputTokens sets the "input_tokens" field.
func (_u *UsageLogUpdate) SetInputTokens(v int) *UsageLogUpdate {
	_u.mutation.ResetInputTokens()
	_u.mutation.SetInputTokens(v)
	return _u
}

// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableInputTokens(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetInputTokens(*v)
	}
	return _u
}

// AddInputTokens adds value to the "input_tokens" field.
func (_u *UsageLogUpdate) AddInputTokens(v int) *UsageLogUpdate {
	_u.mutation.AddInputTokens(v)
	return _u
}

// SetOutputTokens sets the "output_tokens" field.
func (_u *UsageLogUpdate) SetOutputTokens(v int) *UsageLogUpdate {
	_u.mutation.ResetOutputTokens()
	_u.mutation.SetOutputTokens(v)
	return _u
}

// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableOutputTokens(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetOutputTokens(*v)
	}
	return _u
}

// AddOutputTokens adds value to the "output_tokens" field.
func (_u *UsageLogUpdate) AddOutputTokens(v int) *UsageLogUpdate {
	_u.mutation.AddOutputTokens(v)
	return _u
}

// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (_u *UsageLogUpdate) SetCacheCreationTokens(v int) *UsageLogUpdate {
	_u.mutation.ResetCacheCreationTokens()
	_u.mutation.SetCacheCreationTokens(v)
	return _u
}

// SetNillableCacheCreationTokens sets the "cache_creation_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreationTokens(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetCacheCreationTokens(*v)
	}
	return _u
}

// AddCacheCreationTokens adds value to the "cache_creation_tokens" field.
func (_u *UsageLogUpdate) AddCacheCreationTokens(v int) *UsageLogUpdate {
	_u.mutation.AddCacheCreationTokens(v)
	return _u
}

// SetCacheReadTokens sets the "cache_read_tokens" field.
func (_u *UsageLogUpdate) SetCacheReadTokens(v int) *UsageLogUpdate {
	_u.mutation.ResetCacheReadTokens()
	_u.mutation.SetCacheReadTokens(v)
	return _u
}

// SetNillableCacheReadTokens sets the "cache_read_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheReadTokens(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetCacheReadTokens(*v)
	}
	return _u
}

// AddCacheReadTokens adds value to the "cache_read_tokens" field.
func (_u *UsageLogUpdate) AddCacheReadTokens(v int) *UsageLogUpdate {
	_u.mutation.AddCacheReadTokens(v)
	return _u
}

// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdate) SetCacheCreation5mTokens(v int) *UsageLogUpdate {
	_u.mutation.ResetCacheCreation5mTokens()
	_u.mutation.SetCacheCreation5mTokens(v)
	return _u
}

// SetNillableCacheCreation5mTokens sets the "cache_creation_5m_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreation5mTokens(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetCacheCreation5mTokens(*v)
	}
	return _u
}

// AddCacheCreation5mTokens adds value to the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdate) AddCacheCreation5mTokens(v int) *UsageLogUpdate {
	_u.mutation.AddCacheCreation5mTokens(v)
	return _u
}

// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdate) SetCacheCreation1hTokens(v int) *UsageLogUpdate {
	_u.mutation.ResetCacheCreation1hTokens()
	_u.mutation.SetCacheCreation1hTokens(v)
	return _u
}

// SetNillableCacheCreation1hTokens sets the "cache_creation_1h_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreation1hTokens(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetCacheCreation1hTokens(*v)
	}
	return _u
}

// AddCacheCreation1hTokens adds value to the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdate) AddCacheCreation1hTokens(v int) *UsageLogUpdate {
	_u.mutation.AddCacheCreation1hTokens(v)
	return _u
}

// SetInputCost sets the "input_cost" field.
func (_u *UsageLogUpdate) SetInputCost(v float64) *UsageLogUpdate {
	_u.mutation.ResetInputCost()
	_u.mutation.SetInputCost(v)
	return _u
}

// SetNillableInputCost sets the "input_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableInputCost(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetInputCost(*v)
	}
	return _u
}

// AddInputCost adds value to the "input_cost" field.
func (_u *UsageLogUpdate) AddInputCost(v float64) *UsageLogUpdate {
	_u.mutation.AddInputCost(v)
	return _u
}

// SetOutputCost sets the "output_cost" field.
func (_u *UsageLogUpdate) SetOutputCost(v float64) *UsageLogUpdate {
	_u.mutation.ResetOutputCost()
	_u.mutation.SetOutputCost(v)
	return _u
}

// SetNillableOutputCost sets the "output_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableOutputCost(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetOutputCost(*v)
	}
	return _u
}

// AddOutputCost adds value to the "output_cost" field.
func (_u *UsageLogUpdate) AddOutputCost(v float64) *UsageLogUpdate {
	_u.mutation.AddOutputCost(v)
	return _u
}

// SetCacheCreationCost sets the "cache_creation_cost" field.
func (_u *UsageLogUpdate) SetCacheCreationCost(v float64) *UsageLogUpdate {
	_u.mutation.ResetCacheCreationCost()
	_u.mutation.SetCacheCreationCost(v)
	return _u
}

// SetNillableCacheCreationCost sets the "cache_creation_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreationCost(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetCacheCreationCost(*v)
	}
	return _u
}

// AddCacheCreationCost adds value to the "cache_creation_cost" field.
func (_u *UsageLogUpdate) AddCacheCreationCost(v float64) *UsageLogUpdate {
	_u.mutation.AddCacheCreationCost(v)
	return _u
}

// SetCacheReadCost sets the "cache_read_cost" field.
func (_u *UsageLogUpdate) SetCacheReadCost(v float64) *UsageLogUpdate {
	_u.mutation.ResetCacheReadCost()
	_u.mutation.SetCacheReadCost(v)
	return _u
}

// SetNillableCacheReadCost sets the "cache_read_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheReadCost(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetCacheReadCost(*v)
	}
	return _u
}

// AddCacheReadCost adds value to the "cache_read_cost" field.
func (_u *UsageLogUpdate) AddCacheReadCost(v float64) *UsageLogUpdate {
	_u.mutation.AddCacheReadCost(v)
	return _u
}

// SetTotalCost sets the "total_cost" field.
func (_u *UsageLogUpdate) SetTotalCost(v float64) *UsageLogUpdate {
	_u.mutation.ResetTotalCost()
	_u.mutation.SetTotalCost(v)
	return _u
}

// SetNillableTotalCost sets the "total_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableTotalCost(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetTotalCost(*v)
	}
	return _u
}

// AddTotalCost adds value to the "total_cost" field.
func (_u *UsageLogUpdate) AddTotalCost(v float64) *UsageLogUpdate {
	_u.mutation.AddTotalCost(v)
	return _u
}

// SetActualCost sets the "actual_cost" field.
func (_u *UsageLogUpdate) SetActualCost(v float64) *UsageLogUpdate {
	_u.mutation.ResetActualCost()
	_u.mutation.SetActualCost(v)
	return _u
}

// SetNillableActualCost sets the "actual_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableActualCost(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetActualCost(*v)
	}
	return _u
}

// AddActualCost adds value to the "actual_cost" field.
func (_u *UsageLogUpdate) AddActualCost(v float64) *UsageLogUpdate {
	_u.mutation.AddActualCost(v)
	return _u
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *UsageLogUpdate) SetRateMultiplier(v float64) *UsageLogUpdate {
	_u.mutation.ResetRateMultiplier()
	_u.mutation.SetRateMultiplier(v)
	return _u
}

// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableRateMultiplier(v *float64) *UsageLogUpdate {
	if v != nil {
		_u.SetRateMultiplier(*v)
	}
	return _u
}

// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *UsageLogUpdate) AddRateMultiplier(v float64) *UsageLogUpdate {
	_u.mutation.AddRateMultiplier(v)
	return _u
}

// SetBillingType sets the "billing_type" field.
func (_u *UsageLogUpdate) SetBillingType(v int8) *UsageLogUpdate {
	_u.mutation.ResetBillingType()
	_u.mutation.SetBillingType(v)
	return _u
}

// SetNillableBillingType sets the "billing_type" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableBillingType(v *int8) *UsageLogUpdate {
	if v != nil {
		_u.SetBillingType(*v)
	}
	return _u
}

// AddBillingType adds value to the "billing_type" field.
func (_u *UsageLogUpdate) AddBillingType(v int8) *UsageLogUpdate {
	_u.mutation.AddBillingType(v)
	return _u
}

// SetStream sets the "stream" field.
func (_u *UsageLogUpdate) SetStream(v bool) *UsageLogUpdate {
	_u.mutation.SetStream(v)
	return _u
}

// SetNillableStream sets the "stream" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableStream(v *bool) *UsageLogUpdate {
	if v != nil {
		_u.SetStream(*v)
	}
	return _u
}

// SetDurationMs sets the "duration_ms" field.
func (_u *UsageLogUpdate) SetDurationMs(v int) *UsageLogUpdate {
	_u.mutation.ResetDurationMs()
	_u.mutation.SetDurationMs(v)
	return _u
}

// SetNillableDurationMs sets the "duration_ms" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableDurationMs(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetDurationMs(*v)
	}
	return _u
}

// AddDurationMs adds value to the "duration_ms" field.
func (_u *UsageLogUpdate) AddDurationMs(v int) *UsageLogUpdate {
	_u.mutation.AddDurationMs(v)
	return _u
}

// ClearDurationMs clears the value of the "duration_ms" field.
func (_u *UsageLogUpdate) ClearDurationMs() *UsageLogUpdate {
	_u.mutation.ClearDurationMs()
	return _u
}

// SetFirstTokenMs sets the "first_token_ms" field.
func (_u *UsageLogUpdate) SetFirstTokenMs(v int) *UsageLogUpdate {
	_u.mutation.ResetFirstTokenMs()
	_u.mutation.SetFirstTokenMs(v)
	return _u
}

// SetNillableFirstTokenMs sets the "first_token_ms" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableFirstTokenMs(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetFirstTokenMs(*v)
	}
	return _u
}

// AddFirstTokenMs adds value to the "first_token_ms" field.
func (_u *UsageLogUpdate) AddFirstTokenMs(v int) *UsageLogUpdate {
	_u.mutation.AddFirstTokenMs(v)
	return _u
}

// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (_u *UsageLogUpdate) ClearFirstTokenMs() *UsageLogUpdate {
	_u.mutation.ClearFirstTokenMs()
	return _u
}

// SetUserAgent sets the "user_agent" field.
func (_u *UsageLogUpdate) SetUserAgent(v string) *UsageLogUpdate {
	_u.mutation.SetUserAgent(v)
	return _u
}

// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableUserAgent(v *string) *UsageLogUpdate {
	if v != nil {
		_u.SetUserAgent(*v)
	}
	return _u
}

// ClearUserAgent clears the value of the "user_agent" field.
func (_u *UsageLogUpdate) ClearUserAgent() *UsageLogUpdate {
	_u.mutation.ClearUserAgent()
	return _u
}

// SetIPAddress sets the "ip_address" field.
func (_u *UsageLogUpdate) SetIPAddress(v string) *UsageLogUpdate {
	_u.mutation.SetIPAddress(v)
	return _u
}

// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableIPAddress(v *string) *UsageLogUpdate {
	if v != nil {
		_u.SetIPAddress(*v)
	}
	return _u
}

// ClearIPAddress clears the value of the "ip_address" field.
func (_u *UsageLogUpdate) ClearIPAddress() *UsageLogUpdate {
	_u.mutation.ClearIPAddress()
	return _u
}

// SetImageCount sets the "image_count" field.
func (_u *UsageLogUpdate) SetImageCount(v int) *UsageLogUpdate {
	_u.mutation.ResetImageCount()
	_u.mutation.SetImageCount(v)
	return _u
}

// SetNillableImageCount sets the "image_count" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableImageCount(v *int) *UsageLogUpdate {
	if v != nil {
		_u.SetImageCount(*v)
	}
	return _u
}

// AddImageCount adds value to the "image_count" field.
func (_u *UsageLogUpdate) AddImageCount(v int) *UsageLogUpdate {
	_u.mutation.AddImageCount(v)
	return _u
}

// SetImageSize sets the "image_size" field.
func (_u *UsageLogUpdate) SetImageSize(v string) *UsageLogUpdate {
	_u.mutation.SetImageSize(v)
	return _u
}

// SetNillableImageSize sets the "image_size" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableImageSize(v *string) *UsageLogUpdate {
	if v != nil {
		_u.SetImageSize(*v)
	}
	return _u
}

// ClearImageSize clears the value of the "image_size" field.
func (_u *UsageLogUpdate) ClearImageSize() *UsageLogUpdate {
	_u.mutation.ClearImageSize()
	return _u
}

// SetUser sets the "user" edge to the User entity.
func (_u *UsageLogUpdate) SetUser(v *User) *UsageLogUpdate {
	return _u.SetUserID(v.ID)
}

// SetAPIKey sets the "api_key" edge to the APIKey entity.
func (_u *UsageLogUpdate) SetAPIKey(v *APIKey) *UsageLogUpdate {
	return _u.SetAPIKeyID(v.ID)
}

// SetAccount sets the "account" edge to the Account entity.
func (_u *UsageLogUpdate) SetAccount(v *Account) *UsageLogUpdate {
	return _u.SetAccountID(v.ID)
}

// SetGroup sets the "group" edge to the Group entity.
func (_u *UsageLogUpdate) SetGroup(v *Group) *UsageLogUpdate {
	return _u.SetGroupID(v.ID)
}

// SetSubscription sets the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdate) SetSubscription(v *UserSubscription) *UsageLogUpdate {
	return _u.SetSubscriptionID(v.ID)
}

// Mutation returns the UsageLogMutation object of the builder.
func (_u *UsageLogUpdate) Mutation() *UsageLogMutation {
	return _u.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (_u *UsageLogUpdate) ClearUser() *UsageLogUpdate {
	_u.mutation.ClearUser()
	return _u
}

// ClearAPIKey clears the "api_key" edge to the APIKey entity.
func (_u *UsageLogUpdate) ClearAPIKey() *UsageLogUpdate {
	_u.mutation.ClearAPIKey()
	return _u
}

// ClearAccount clears the "account" edge to the Account entity.
func (_u *UsageLogUpdate) ClearAccount() *UsageLogUpdate {
	_u.mutation.ClearAccount()
	return _u
}

// ClearGroup clears the "group" edge to the Group entity.
func (_u *UsageLogUpdate) ClearGroup() *UsageLogUpdate {
	_u.mutation.ClearGroup()
	return _u
}

// ClearSubscription clears the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdate) ClearSubscription() *UsageLogUpdate {
	_u.mutation.ClearSubscription()
	return _u
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *UsageLogUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *UsageLogUpdate) check() error {
	if v, ok := _u.mutation.RequestID(); ok {
		if err := usagelog.RequestIDValidator(v); err != nil {
			return &ValidationError{Name: "request_id", err: fmt.Errorf(`ent: validator failed for field "UsageLog.request_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Model(); ok {
		if err := usagelog.ModelValidator(v); err != nil {
			return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "UsageLog.model": %w`, err)}
		}
	}
	if v, ok := _u.mutation.UserAgent(); ok {
		if err := usagelog.UserAgentValidator(v); err != nil {
			return &ValidationError{Name: "user_agent", err: fmt.Errorf(`ent: validator failed for field "UsageLog.user_agent": %w`, err)}
		}
	}
	if v, ok := _u.mutation.IPAddress(); ok {
		if err := usagelog.IPAddressValidator(v); err != nil {
			return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "UsageLog.ip_address": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ImageSize(); ok {
		if err := usagelog.ImageSizeValidator(v); err != nil {
			return &ValidationError{Name: "image_size", err: fmt.Errorf(`ent: validator failed for field "UsageLog.image_size": %w`, err)}
		}
	}
	if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UsageLog.user"`)
	}
	if _u.mutation.APIKeyCleared() && len(_u.mutation.APIKeyIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UsageLog.api_key"`)
	}
	if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UsageLog.account"`)
	}
	return nil
}

func (_u *UsageLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(usagelog.Table, usagelog.Columns, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.RequestID(); ok {
		_spec.SetField(usagelog.FieldRequestID, field.TypeString, value)
	}
	if value, ok := _u.mutation.Model(); ok {
		_spec.SetField(usagelog.FieldModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.InputTokens(); ok {
		_spec.SetField(usagelog.FieldInputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedInputTokens(); ok {
		_spec.AddField(usagelog.FieldInputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.OutputTokens(); ok {
		_spec.SetField(usagelog.FieldOutputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedOutputTokens(); ok {
		_spec.AddField(usagelog.FieldOutputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheCreationTokens(); ok {
		_spec.SetField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheCreationTokens(); ok {
		_spec.AddField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheReadTokens(); ok {
		_spec.SetField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheReadTokens(); ok {
		_spec.AddField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheCreation5mTokens(); ok {
		_spec.SetField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheCreation5mTokens(); ok {
		_spec.AddField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheCreation1hTokens(); ok {
		_spec.SetField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheCreation1hTokens(); ok {
		_spec.AddField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.InputCost(); ok {
		_spec.SetField(usagelog.FieldInputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedInputCost(); ok {
		_spec.AddField(usagelog.FieldInputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.OutputCost(); ok {
		_spec.SetField(usagelog.FieldOutputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedOutputCost(); ok {
		_spec.AddField(usagelog.FieldOutputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.CacheCreationCost(); ok {
		_spec.SetField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedCacheCreationCost(); ok {
		_spec.AddField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.CacheReadCost(); ok {
		_spec.SetField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedCacheReadCost(); ok {
		_spec.AddField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.TotalCost(); ok {
		_spec.SetField(usagelog.FieldTotalCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedTotalCost(); ok {
		_spec.AddField(usagelog.FieldTotalCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.ActualCost(); ok {
		_spec.SetField(usagelog.FieldActualCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedActualCost(); ok {
		_spec.AddField(usagelog.FieldActualCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RateMultiplier(); ok {
		_spec.SetField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRateMultiplier(); ok {
		_spec.AddField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.BillingType(); ok {
		_spec.SetField(usagelog.FieldBillingType, field.TypeInt8, value)
	}
	if value, ok := _u.mutation.AddedBillingType(); ok {
		_spec.AddField(usagelog.FieldBillingType, field.TypeInt8, value)
	}
	if value, ok := _u.mutation.Stream(); ok {
		_spec.SetField(usagelog.FieldStream, field.TypeBool, value)
	}
	if value, ok := _u.mutation.DurationMs(); ok {
		_spec.SetField(usagelog.FieldDurationMs, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDurationMs(); ok {
		_spec.AddField(usagelog.FieldDurationMs, field.TypeInt, value)
	}
	if _u.mutation.DurationMsCleared() {
		_spec.ClearField(usagelog.FieldDurationMs, field.TypeInt)
	}
	if value, ok := _u.mutation.FirstTokenMs(); ok {
		_spec.SetField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedFirstTokenMs(); ok {
		_spec.AddField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
	}
	if _u.mutation.FirstTokenMsCleared() {
		_spec.ClearField(usagelog.FieldFirstTokenMs, field.TypeInt)
	}
	if value, ok := _u.mutation.UserAgent(); ok {
		_spec.SetField(usagelog.FieldUserAgent, field.TypeString, value)
	}
	if _u.mutation.UserAgentCleared() {
		_spec.ClearField(usagelog.FieldUserAgent, field.TypeString)
	}
	if value, ok := _u.mutation.IPAddress(); ok {
		_spec.SetField(usagelog.FieldIPAddress, field.TypeString, value)
	}
	if _u.mutation.IPAddressCleared() {
		_spec.ClearField(usagelog.FieldIPAddress, field.TypeString)
	}
	if value, ok := _u.mutation.ImageCount(); ok {
		_spec.SetField(usagelog.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedImageCount(); ok {
		_spec.AddField(usagelog.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ImageSize(); ok {
		_spec.SetField(usagelog.FieldImageSize, field.TypeString, value)
	}
	if _u.mutation.ImageSizeCleared() {
		_spec.ClearField(usagelog.FieldImageSize, field.TypeString)
	}
	if _u.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.UserTable,
			Columns: []string{usagelog.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.UserTable,
			Columns: []string{usagelog.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.APIKeyCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.APIKeyTable,
			Columns: []string{usagelog.APIKeyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.APIKeyIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.APIKeyTable,
			Columns: []string{usagelog.APIKeyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.AccountCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.AccountTable,
			Columns: []string{usagelog.AccountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.AccountTable,
			Columns: []string{usagelog.AccountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.GroupCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.GroupTable,
			Columns: []string{usagelog.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.GroupTable,
			Columns: []string{usagelog.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.SubscriptionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.SubscriptionTable,
			Columns: []string{usagelog.SubscriptionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SubscriptionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.SubscriptionTable,
			Columns: []string{usagelog.SubscriptionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usagelog.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// UsageLogUpdateOne is the builder for updating a single UsageLog entity.
type UsageLogUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UsageLogMutation
}

// SetUserID sets the "user_id" field.
func (_u *UsageLogUpdateOne) SetUserID(v int64) *UsageLogUpdateOne {
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableUserID(v *int64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// SetAPIKeyID sets the "api_key_id" field.
func (_u *UsageLogUpdateOne) SetAPIKeyID(v int64) *UsageLogUpdateOne {
	_u.mutation.SetAPIKeyID(v)
	return _u
}

// SetNillableAPIKeyID sets the "api_key_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableAPIKeyID(v *int64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetAPIKeyID(*v)
	}
	return _u
}

// SetAccountID sets the "account_id" field.
func (_u *UsageLogUpdateOne) SetAccountID(v int64) *UsageLogUpdateOne {
	_u.mutation.SetAccountID(v)
	return _u
}

// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableAccountID(v *int64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetAccountID(*v)
	}
	return _u
}

// SetRequestID sets the "request_id" field.
func (_u *UsageLogUpdateOne) SetRequestID(v string) *UsageLogUpdateOne {
	_u.mutation.SetRequestID(v)
	return _u
}

// SetNillableRequestID sets the "request_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableRequestID(v *string) *UsageLogUpdateOne {
	if v != nil {
		_u.SetRequestID(*v)
	}
	return _u
}

// SetModel sets the "model" field.
func (_u *UsageLogUpdateOne) SetModel(v string) *UsageLogUpdateOne {
	_u.mutation.SetModel(v)
	return _u
}

// SetNillableModel sets the "model" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableModel(v *string) *UsageLogUpdateOne {
	if v != nil {
		_u.SetModel(*v)
	}
	return _u
}

// SetGroupID sets the "group_id" field.
func (_u *UsageLogUpdateOne) SetGroupID(v int64) *UsageLogUpdateOne {
	_u.mutation.SetGroupID(v)
	return _u
}

// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableGroupID(v *int64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetGroupID(*v)
	}
	return _u
}

// ClearGroupID clears the value of the "group_id" field.
func (_u *UsageLogUpdateOne) ClearGroupID() *UsageLogUpdateOne {
	_u.mutation.ClearGroupID()
	return _u
}

// SetSubscriptionID sets the "subscription_id" field.
func (_u *UsageLogUpdateOne) SetSubscriptionID(v int64) *UsageLogUpdateOne {
	_u.mutation.SetSubscriptionID(v)
	return _u
}

// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableSubscriptionID(v *int64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetSubscriptionID(*v)
	}
	return _u
}

// ClearSubscriptionID clears the value of the "subscription_id" field.
func (_u *UsageLogUpdateOne) ClearSubscriptionID() *UsageLogUpdateOne {
	_u.mutation.ClearSubscriptionID()
	return _u
}

// SetInputTokens sets the "input_tokens" field.
func (_u *UsageLogUpdateOne) SetInputTokens(v int) *UsageLogUpdateOne {
	_u.mutation.ResetInputTokens()
	_u.mutation.SetInputTokens(v)
	return _u
}

// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableInputTokens(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetInputTokens(*v)
	}
	return _u
}

// AddInputTokens adds value to the "input_tokens" field.
func (_u *UsageLogUpdateOne) AddInputTokens(v int) *UsageLogUpdateOne {
	_u.mutation.AddInputTokens(v)
	return _u
}

// SetOutputTokens sets the "output_tokens" field.
func (_u *UsageLogUpdateOne) SetOutputTokens(v int) *UsageLogUpdateOne {
	_u.mutation.ResetOutputTokens()
	_u.mutation.SetOutputTokens(v)
	return _u
}

// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableOutputTokens(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetOutputTokens(*v)
	}
	return _u
}

// AddOutputTokens adds value to the "output_tokens" field.
func (_u *UsageLogUpdateOne) AddOutputTokens(v int) *UsageLogUpdateOne {
	_u.mutation.AddOutputTokens(v)
	return _u
}

// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheCreationTokens(v int) *UsageLogUpdateOne {
	_u.mutation.ResetCacheCreationTokens()
	_u.mutation.SetCacheCreationTokens(v)
	return _u
}

// SetNillableCacheCreationTokens sets the "cache_creation_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreationTokens(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetCacheCreationTokens(*v)
	}
	return _u
}

// AddCacheCreationTokens adds value to the "cache_creation_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheCreationTokens(v int) *UsageLogUpdateOne {
	_u.mutation.AddCacheCreationTokens(v)
	return _u
}

// SetCacheReadTokens sets the "cache_read_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheReadTokens(v int) *UsageLogUpdateOne {
	_u.mutation.ResetCacheReadTokens()
	_u.mutation.SetCacheReadTokens(v)
	return _u
}

// SetNillableCacheReadTokens sets the "cache_read_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheReadTokens(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetCacheReadTokens(*v)
	}
	return _u
}

// AddCacheReadTokens adds value to the "cache_read_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheReadTokens(v int) *UsageLogUpdateOne {
	_u.mutation.AddCacheReadTokens(v)
	return _u
}

// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheCreation5mTokens(v int) *UsageLogUpdateOne {
	_u.mutation.ResetCacheCreation5mTokens()
	_u.mutation.SetCacheCreation5mTokens(v)
	return _u
}

// SetNillableCacheCreation5mTokens sets the "cache_creation_5m_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreation5mTokens(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetCacheCreation5mTokens(*v)
	}
	return _u
}

// AddCacheCreation5mTokens adds value to the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheCreation5mTokens(v int) *UsageLogUpdateOne {
	_u.mutation.AddCacheCreation5mTokens(v)
	return _u
}

// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheCreation1hTokens(v int) *UsageLogUpdateOne {
	_u.mutation.ResetCacheCreation1hTokens()
	_u.mutation.SetCacheCreation1hTokens(v)
	return _u
}

// SetNillableCacheCreation1hTokens sets the "cache_creation_1h_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreation1hTokens(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetCacheCreation1hTokens(*v)
	}
	return _u
}

// AddCacheCreation1hTokens adds value to the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheCreation1hTokens(v int) *UsageLogUpdateOne {
	_u.mutation.AddCacheCreation1hTokens(v)
	return _u
}

// SetInputCost sets the "input_cost" field.
func (_u *UsageLogUpdateOne) SetInputCost(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetInputCost()
	_u.mutation.SetInputCost(v)
	return _u
}

// SetNillableInputCost sets the "input_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableInputCost(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetInputCost(*v)
	}
	return _u
}

// AddInputCost adds value to the "input_cost" field.
func (_u *UsageLogUpdateOne) AddInputCost(v float64) *UsageLogUpdateOne {
	_u.mutation.AddInputCost(v)
	return _u
}

// SetOutputCost sets the "output_cost" field.
func (_u *UsageLogUpdateOne) SetOutputCost(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetOutputCost()
	_u.mutation.SetOutputCost(v)
	return _u
}

// SetNillableOutputCost sets the "output_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableOutputCost(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetOutputCost(*v)
	}
	return _u
}

// AddOutputCost adds value to the "output_cost" field.
func (_u *UsageLogUpdateOne) AddOutputCost(v float64) *UsageLogUpdateOne {
	_u.mutation.AddOutputCost(v)
	return _u
}

// SetCacheCreationCost sets the "cache_creation_cost" field.
func (_u *UsageLogUpdateOne) SetCacheCreationCost(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetCacheCreationCost()
	_u.mutation.SetCacheCreationCost(v)
	return _u
}

// SetNillableCacheCreationCost sets the "cache_creation_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreationCost(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetCacheCreationCost(*v)
	}
	return _u
}

// AddCacheCreationCost adds value to the "cache_creation_cost" field.
func (_u *UsageLogUpdateOne) AddCacheCreationCost(v float64) *UsageLogUpdateOne {
	_u.mutation.AddCacheCreationCost(v)
	return _u
}

// SetCacheReadCost sets the "cache_read_cost" field.
func (_u *UsageLogUpdateOne) SetCacheReadCost(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetCacheReadCost()
	_u.mutation.SetCacheReadCost(v)
	return _u
}

// SetNillableCacheReadCost sets the "cache_read_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheReadCost(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetCacheReadCost(*v)
	}
	return _u
}

// AddCacheReadCost adds value to the "cache_read_cost" field.
func (_u *UsageLogUpdateOne) AddCacheReadCost(v float64) *UsageLogUpdateOne {
	_u.mutation.AddCacheReadCost(v)
	return _u
}

// SetTotalCost sets the "total_cost" field.
func (_u *UsageLogUpdateOne) SetTotalCost(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetTotalCost()
	_u.mutation.SetTotalCost(v)
	return _u
}

// SetNillableTotalCost sets the "total_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableTotalCost(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetTotalCost(*v)
	}
	return _u
}

// AddTotalCost adds value to the "total_cost" field.
func (_u *UsageLogUpdateOne) AddTotalCost(v float64) *UsageLogUpdateOne {
	_u.mutation.AddTotalCost(v)
	return _u
}

// SetActualCost sets the "actual_cost" field.
func (_u *UsageLogUpdateOne) SetActualCost(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetActualCost()
	_u.mutation.SetActualCost(v)
	return _u
}

// SetNillableActualCost sets the "actual_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableActualCost(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetActualCost(*v)
	}
	return _u
}

// AddActualCost adds value to the "actual_cost" field.
func (_u *UsageLogUpdateOne) AddActualCost(v float64) *UsageLogUpdateOne {
	_u.mutation.AddActualCost(v)
	return _u
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *UsageLogUpdateOne) SetRateMultiplier(v float64) *UsageLogUpdateOne {
	_u.mutation.ResetRateMultiplier()
	_u.mutation.SetRateMultiplier(v)
	return _u
}

// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableRateMultiplier(v *float64) *UsageLogUpdateOne {
	if v != nil {
		_u.SetRateMultiplier(*v)
	}
	return _u
}

// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *UsageLogUpdateOne) AddRateMultiplier(v float64) *UsageLogUpdateOne {
	_u.mutation.AddRateMultiplier(v)
	return _u
}

// SetBillingType sets the "billing_type" field.
func (_u *UsageLogUpdateOne) SetBillingType(v int8) *UsageLogUpdateOne {
	_u.mutation.ResetBillingType()
	_u.mutation.SetBillingType(v)
	return _u
}

// SetNillableBillingType sets the "billing_type" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableBillingType(v *int8) *UsageLogUpdateOne {
	if v != nil {
		_u.SetBillingType(*v)
	}
	return _u
}

// AddBillingType adds value to the "billing_type" field.
func (_u *UsageLogUpdateOne) AddBillingType(v int8) *UsageLogUpdateOne {
	_u.mutation.AddBillingType(v)
	return _u
}

// SetStream sets the "stream" field.
func (_u *UsageLogUpdateOne) SetStream(v bool) *UsageLogUpdateOne {
	_u.mutation.SetStream(v)
	return _u
}

// SetNillableStream sets the "stream" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableStream(v *bool) *UsageLogUpdateOne {
	if v != nil {
		_u.SetStream(*v)
	}
	return _u
}

// SetDurationMs sets the "duration_ms" field.
func (_u *UsageLogUpdateOne) SetDurationMs(v int) *UsageLogUpdateOne {
	_u.mutation.ResetDurationMs()
	_u.mutation.SetDurationMs(v)
	return _u
}

// SetNillableDurationMs sets the "duration_ms" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableDurationMs(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetDurationMs(*v)
	}
	return _u
}

// AddDurationMs adds value to the "duration_ms" field.
func (_u *UsageLogUpdateOne) AddDurationMs(v int) *UsageLogUpdateOne {
	_u.mutation.AddDurationMs(v)
	return _u
}

// ClearDurationMs clears the value of the "duration_ms" field.
func (_u *UsageLogUpdateOne) ClearDurationMs() *UsageLogUpdateOne {
	_u.mutation.ClearDurationMs()
	return _u
}

// SetFirstTokenMs sets the "first_token_ms" field.
func (_u *UsageLogUpdateOne) SetFirstTokenMs(v int) *UsageLogUpdateOne {
	_u.mutation.ResetFirstTokenMs()
	_u.mutation.SetFirstTokenMs(v)
	return _u
}

// SetNillableFirstTokenMs sets the "first_token_ms" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableFirstTokenMs(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetFirstTokenMs(*v)
	}
	return _u
}

// AddFirstTokenMs adds value to the "first_token_ms" field.
func (_u *UsageLogUpdateOne) AddFirstTokenMs(v int) *UsageLogUpdateOne {
	_u.mutation.AddFirstTokenMs(v)
	return _u
}

// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (_u *UsageLogUpdateOne) ClearFirstTokenMs() *UsageLogUpdateOne {
	_u.mutation.ClearFirstTokenMs()
	return _u
}

// SetUserAgent sets the "user_agent" field.
func (_u *UsageLogUpdateOne) SetUserAgent(v string) *UsageLogUpdateOne {
	_u.mutation.SetUserAgent(v)
	return _u
}

// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableUserAgent(v *string) *UsageLogUpdateOne {
	if v != nil {
		_u.SetUserAgent(*v)
	}
	return _u
}

// ClearUserAgent clears the value of the "user_agent" field.
func (_u *UsageLogUpdateOne) ClearUserAgent() *UsageLogUpdateOne {
	_u.mutation.ClearUserAgent()
	return _u
}

// SetIPAddress sets the "ip_address" field.
func (_u *UsageLogUpdateOne) SetIPAddress(v string) *UsageLogUpdateOne {
	_u.mutation.SetIPAddress(v)
	return _u
}

// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableIPAddress(v *string) *UsageLogUpdateOne {
	if v != nil {
		_u.SetIPAddress(*v)
	}
	return _u
}

// ClearIPAddress clears the value of the "ip_address" field.
func (_u *UsageLogUpdateOne) ClearIPAddress() *UsageLogUpdateOne {
	_u.mutation.ClearIPAddress()
	return _u
}

// SetImageCount sets the "image_count" field.
func (_u *UsageLogUpdateOne) SetImageCount(v int) *UsageLogUpdateOne {
	_u.mutation.ResetImageCount()
	_u.mutation.SetImageCount(v)
	return _u
}

// SetNillableImageCount sets the "image_count" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableImageCount(v *int) *UsageLogUpdateOne {
	if v != nil {
		_u.SetImageCount(*v)
	}
	return _u
}

// AddImageCount adds value to the "image_count" field.
func (_u *UsageLogUpdateOne) AddImageCount(v int) *UsageLogUpdateOne {
	_u.mutation.AddImageCount(v)
	return _u
}

// SetImageSize sets the "image_size" field.
func (_u *UsageLogUpdateOne) SetImageSize(v string) *UsageLogUpdateOne {
	_u.mutation.SetImageSize(v)
	return _u
}

// SetNillableImageSize sets the "image_size" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableImageSize(v *string) *UsageLogUpdateOne {
	if v != nil {
		_u.SetImageSize(*v)
	}
	return _u
}

// ClearImageSize clears the value of the "image_size" field.
func (_u *UsageLogUpdateOne) ClearImageSize() *UsageLogUpdateOne {
	_u.mutation.ClearImageSize()
	return _u
}

// SetUser sets the "user" edge to the User entity.
func (_u *UsageLogUpdateOne) SetUser(v *User) *UsageLogUpdateOne {
	return _u.SetUserID(v.ID)
}

// SetAPIKey sets the "api_key" edge to the APIKey entity.
func (_u *UsageLogUpdateOne) SetAPIKey(v *APIKey) *UsageLogUpdateOne {
	return _u.SetAPIKeyID(v.ID)
}

// SetAccount sets the "account" edge to the Account entity.
func (_u *UsageLogUpdateOne) SetAccount(v *Account) *UsageLogUpdateOne {
	return _u.SetAccountID(v.ID)
}

// SetGroup sets the "group" edge to the Group entity.
func (_u *UsageLogUpdateOne) SetGroup(v *Group) *UsageLogUpdateOne {
	return _u.SetGroupID(v.ID)
}

// SetSubscription sets the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdateOne) SetSubscription(v *UserSubscription) *UsageLogUpdateOne {
	return _u.SetSubscriptionID(v.ID)
}

// Mutation returns the UsageLogMutation object of the builder.
func (_u *UsageLogUpdateOne) Mutation() *UsageLogMutation {
	return _u.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (_u *UsageLogUpdateOne) ClearUser() *UsageLogUpdateOne {
	_u.mutation.ClearUser()
	return _u
}

// ClearAPIKey clears the "api_key" edge to the APIKey entity.
func (_u *UsageLogUpdateOne) ClearAPIKey() *UsageLogUpdateOne {
	_u.mutation.ClearAPIKey()
	return _u
}

// ClearAccount clears the "account" edge to the Account entity.
func (_u *UsageLogUpdateOne) ClearAccount() *UsageLogUpdateOne {
	_u.mutation.ClearAccount()
	return _u
}

// ClearGroup clears the "group" edge to the Group entity.
func (_u *UsageLogUpdateOne) ClearGroup() *UsageLogUpdateOne {
	_u.mutation.ClearGroup()
	return _u
}

// ClearSubscription clears the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdateOne) ClearSubscription() *UsageLogUpdateOne {
	_u.mutation.ClearSubscription()
	return _u
}

// Where appends a list predicates to the UsageLogUpdate builder.
func (_u *UsageLogUpdateOne) Where(ps ...predicate.UsageLog) *UsageLogUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

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

// Save executes the query and returns the updated UsageLog entity.
func (_u *UsageLogUpdateOne) Save(ctx context.Context) (*UsageLog, error) {
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *UsageLogUpdateOne) check() error {
	if v, ok := _u.mutation.RequestID(); ok {
		if err := usagelog.RequestIDValidator(v); err != nil {
			return &ValidationError{Name: "request_id", err: fmt.Errorf(`ent: validator failed for field "UsageLog.request_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Model(); ok {
		if err := usagelog.ModelValidator(v); err != nil {
			return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "UsageLog.model": %w`, err)}
		}
	}
	if v, ok := _u.mutation.UserAgent(); ok {
		if err := usagelog.UserAgentValidator(v); err != nil {
			return &ValidationError{Name: "user_agent", err: fmt.Errorf(`ent: validator failed for field "UsageLog.user_agent": %w`, err)}
		}
	}
	if v, ok := _u.mutation.IPAddress(); ok {
		if err := usagelog.IPAddressValidator(v); err != nil {
			return &ValidationError{Name: "ip_address", err: fmt.Errorf(`ent: validator failed for field "UsageLog.ip_address": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ImageSize(); ok {
		if err := usagelog.ImageSizeValidator(v); err != nil {
			return &ValidationError{Name: "image_size", err: fmt.Errorf(`ent: validator failed for field "UsageLog.image_size": %w`, err)}
		}
	}
	if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UsageLog.user"`)
	}
	if _u.mutation.APIKeyCleared() && len(_u.mutation.APIKeyIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UsageLog.api_key"`)
	}
	if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UsageLog.account"`)
	}
	return nil
}

func (_u *UsageLogUpdateOne) sqlSave(ctx context.Context) (_node *UsageLog, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(usagelog.Table, usagelog.Columns, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageLog.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, usagelog.FieldID)
		for _, f := range fields {
			if !usagelog.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != usagelog.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.RequestID(); ok {
		_spec.SetField(usagelog.FieldRequestID, field.TypeString, value)
	}
	if value, ok := _u.mutation.Model(); ok {
		_spec.SetField(usagelog.FieldModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.InputTokens(); ok {
		_spec.SetField(usagelog.FieldInputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedInputTokens(); ok {
		_spec.AddField(usagelog.FieldInputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.OutputTokens(); ok {
		_spec.SetField(usagelog.FieldOutputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedOutputTokens(); ok {
		_spec.AddField(usagelog.FieldOutputTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheCreationTokens(); ok {
		_spec.SetField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheCreationTokens(); ok {
		_spec.AddField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheReadTokens(); ok {
		_spec.SetField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheReadTokens(); ok {
		_spec.AddField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheCreation5mTokens(); ok {
		_spec.SetField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheCreation5mTokens(); ok {
		_spec.AddField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.CacheCreation1hTokens(); ok {
		_spec.SetField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedCacheCreation1hTokens(); ok {
		_spec.AddField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
	}
	if value, ok := _u.mutation.InputCost(); ok {
		_spec.SetField(usagelog.FieldInputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedInputCost(); ok {
		_spec.AddField(usagelog.FieldInputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.OutputCost(); ok {
		_spec.SetField(usagelog.FieldOutputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedOutputCost(); ok {
		_spec.AddField(usagelog.FieldOutputCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.CacheCreationCost(); ok {
		_spec.SetField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedCacheCreationCost(); ok {
		_spec.AddField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.CacheReadCost(); ok {
		_spec.SetField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedCacheReadCost(); ok {
		_spec.AddField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.TotalCost(); ok {
		_spec.SetField(usagelog.FieldTotalCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedTotalCost(); ok {
		_spec.AddField(usagelog.FieldTotalCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.ActualCost(); ok {
		_spec.SetField(usagelog.FieldActualCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedActualCost(); ok {
		_spec.AddField(usagelog.FieldActualCost, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RateMultiplier(); ok {
		_spec.SetField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRateMultiplier(); ok {
		_spec.AddField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.BillingType(); ok {
		_spec.SetField(usagelog.FieldBillingType, field.TypeInt8, value)
	}
	if value, ok := _u.mutation.AddedBillingType(); ok {
		_spec.AddField(usagelog.FieldBillingType, field.TypeInt8, value)
	}
	if value, ok := _u.mutation.Stream(); ok {
		_spec.SetField(usagelog.FieldStream, field.TypeBool, value)
	}
	if value, ok := _u.mutation.DurationMs(); ok {
		_spec.SetField(usagelog.FieldDurationMs, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDurationMs(); ok {
		_spec.AddField(usagelog.FieldDurationMs, field.TypeInt, value)
	}
	if _u.mutation.DurationMsCleared() {
		_spec.ClearField(usagelog.FieldDurationMs, field.TypeInt)
	}
	if value, ok := _u.mutation.FirstTokenMs(); ok {
		_spec.SetField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedFirstTokenMs(); ok {
		_spec.AddField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
	}
	if _u.mutation.FirstTokenMsCleared() {
		_spec.ClearField(usagelog.FieldFirstTokenMs, field.TypeInt)
	}
	if value, ok := _u.mutation.UserAgent(); ok {
		_spec.SetField(usagelog.FieldUserAgent, field.TypeString, value)
	}
	if _u.mutation.UserAgentCleared() {
		_spec.ClearField(usagelog.FieldUserAgent, field.TypeString)
	}
	if value, ok := _u.mutation.IPAddress(); ok {
		_spec.SetField(usagelog.FieldIPAddress, field.TypeString, value)
	}
	if _u.mutation.IPAddressCleared() {
		_spec.ClearField(usagelog.FieldIPAddress, field.TypeString)
	}
	if value, ok := _u.mutation.ImageCount(); ok {
		_spec.SetField(usagelog.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedImageCount(); ok {
		_spec.AddField(usagelog.FieldImageCount, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ImageSize(); ok {
		_spec.SetField(usagelog.FieldImageSize, field.TypeString, value)
	}
	if _u.mutation.ImageSizeCleared() {
		_spec.ClearField(usagelog.FieldImageSize, field.TypeString)
	}
	if _u.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.UserTable,
			Columns: []string{usagelog.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.UserTable,
			Columns: []string{usagelog.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.APIKeyCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.APIKeyTable,
			Columns: []string{usagelog.APIKeyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.APIKeyIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.APIKeyTable,
			Columns: []string{usagelog.APIKeyColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.AccountCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.AccountTable,
			Columns: []string{usagelog.AccountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.AccountTable,
			Columns: []string{usagelog.AccountColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.GroupCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.GroupTable,
			Columns: []string{usagelog.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.GroupTable,
			Columns: []string{usagelog.GroupColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.SubscriptionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.SubscriptionTable,
			Columns: []string{usagelog.SubscriptionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SubscriptionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usagelog.SubscriptionTable,
			Columns: []string{usagelog.SubscriptionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &UsageLog{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usagelog.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
