// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/dialect/sql/sqljson"
	"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/redeemcode"
	"github.com/Wei-Shaw/sub2api/ent/usagelog"
	"github.com/Wei-Shaw/sub2api/ent/user"
	"github.com/Wei-Shaw/sub2api/ent/usersubscription"
	"github.com/Wei-Shaw/sub2api/internal/domain"
)

// GroupUpdate is the builder for updating Group entities.
type GroupUpdate struct {
	config
	hooks    []Hook
	mutation *GroupMutation
}

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

// SetUpdatedAt sets the "updated_at" field.
func (_u *GroupUpdate) SetUpdatedAt(v time.Time) *GroupUpdate {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *GroupUpdate) SetDeletedAt(v time.Time) *GroupUpdate {
	_u.mutation.SetDeletedAt(v)
	return _u
}

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

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

// SetName sets the "name" field.
func (_u *GroupUpdate) SetName(v string) *GroupUpdate {
	_u.mutation.SetName(v)
	return _u
}

// SetNillableName sets the "name" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableName(v *string) *GroupUpdate {
	if v != nil {
		_u.SetName(*v)
	}
	return _u
}

// SetDescription sets the "description" field.
func (_u *GroupUpdate) SetDescription(v string) *GroupUpdate {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableDescription(v *string) *GroupUpdate {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *GroupUpdate) ClearDescription() *GroupUpdate {
	_u.mutation.ClearDescription()
	return _u
}

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

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

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

// SetIsExclusive sets the "is_exclusive" field.
func (_u *GroupUpdate) SetIsExclusive(v bool) *GroupUpdate {
	_u.mutation.SetIsExclusive(v)
	return _u
}

// SetNillableIsExclusive sets the "is_exclusive" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableIsExclusive(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetIsExclusive(*v)
	}
	return _u
}

// SetStatus sets the "status" field.
func (_u *GroupUpdate) SetStatus(v string) *GroupUpdate {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableStatus(v *string) *GroupUpdate {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetPlatform sets the "platform" field.
func (_u *GroupUpdate) SetPlatform(v string) *GroupUpdate {
	_u.mutation.SetPlatform(v)
	return _u
}

// SetNillablePlatform sets the "platform" field if the given value is not nil.
func (_u *GroupUpdate) SetNillablePlatform(v *string) *GroupUpdate {
	if v != nil {
		_u.SetPlatform(*v)
	}
	return _u
}

// SetSubscriptionType sets the "subscription_type" field.
func (_u *GroupUpdate) SetSubscriptionType(v string) *GroupUpdate {
	_u.mutation.SetSubscriptionType(v)
	return _u
}

// SetNillableSubscriptionType sets the "subscription_type" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableSubscriptionType(v *string) *GroupUpdate {
	if v != nil {
		_u.SetSubscriptionType(*v)
	}
	return _u
}

// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (_u *GroupUpdate) SetDailyLimitUsd(v float64) *GroupUpdate {
	_u.mutation.ResetDailyLimitUsd()
	_u.mutation.SetDailyLimitUsd(v)
	return _u
}

// SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableDailyLimitUsd(v *float64) *GroupUpdate {
	if v != nil {
		_u.SetDailyLimitUsd(*v)
	}
	return _u
}

// AddDailyLimitUsd adds value to the "daily_limit_usd" field.
func (_u *GroupUpdate) AddDailyLimitUsd(v float64) *GroupUpdate {
	_u.mutation.AddDailyLimitUsd(v)
	return _u
}

// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
func (_u *GroupUpdate) ClearDailyLimitUsd() *GroupUpdate {
	_u.mutation.ClearDailyLimitUsd()
	return _u
}

// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (_u *GroupUpdate) SetWeeklyLimitUsd(v float64) *GroupUpdate {
	_u.mutation.ResetWeeklyLimitUsd()
	_u.mutation.SetWeeklyLimitUsd(v)
	return _u
}

// SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableWeeklyLimitUsd(v *float64) *GroupUpdate {
	if v != nil {
		_u.SetWeeklyLimitUsd(*v)
	}
	return _u
}

// AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
func (_u *GroupUpdate) AddWeeklyLimitUsd(v float64) *GroupUpdate {
	_u.mutation.AddWeeklyLimitUsd(v)
	return _u
}

// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
func (_u *GroupUpdate) ClearWeeklyLimitUsd() *GroupUpdate {
	_u.mutation.ClearWeeklyLimitUsd()
	return _u
}

// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (_u *GroupUpdate) SetMonthlyLimitUsd(v float64) *GroupUpdate {
	_u.mutation.ResetMonthlyLimitUsd()
	_u.mutation.SetMonthlyLimitUsd(v)
	return _u
}

// SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableMonthlyLimitUsd(v *float64) *GroupUpdate {
	if v != nil {
		_u.SetMonthlyLimitUsd(*v)
	}
	return _u
}

// AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
func (_u *GroupUpdate) AddMonthlyLimitUsd(v float64) *GroupUpdate {
	_u.mutation.AddMonthlyLimitUsd(v)
	return _u
}

// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
func (_u *GroupUpdate) ClearMonthlyLimitUsd() *GroupUpdate {
	_u.mutation.ClearMonthlyLimitUsd()
	return _u
}

// SetDefaultValidityDays sets the "default_validity_days" field.
func (_u *GroupUpdate) SetDefaultValidityDays(v int) *GroupUpdate {
	_u.mutation.ResetDefaultValidityDays()
	_u.mutation.SetDefaultValidityDays(v)
	return _u
}

// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableDefaultValidityDays(v *int) *GroupUpdate {
	if v != nil {
		_u.SetDefaultValidityDays(*v)
	}
	return _u
}

// AddDefaultValidityDays adds value to the "default_validity_days" field.
func (_u *GroupUpdate) AddDefaultValidityDays(v int) *GroupUpdate {
	_u.mutation.AddDefaultValidityDays(v)
	return _u
}

// SetImagePrice1k sets the "image_price_1k" field.
func (_u *GroupUpdate) SetImagePrice1k(v float64) *GroupUpdate {
	_u.mutation.ResetImagePrice1k()
	_u.mutation.SetImagePrice1k(v)
	return _u
}

// SetNillableImagePrice1k sets the "image_price_1k" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableImagePrice1k(v *float64) *GroupUpdate {
	if v != nil {
		_u.SetImagePrice1k(*v)
	}
	return _u
}

// AddImagePrice1k adds value to the "image_price_1k" field.
func (_u *GroupUpdate) AddImagePrice1k(v float64) *GroupUpdate {
	_u.mutation.AddImagePrice1k(v)
	return _u
}

// ClearImagePrice1k clears the value of the "image_price_1k" field.
func (_u *GroupUpdate) ClearImagePrice1k() *GroupUpdate {
	_u.mutation.ClearImagePrice1k()
	return _u
}

// SetImagePrice2k sets the "image_price_2k" field.
func (_u *GroupUpdate) SetImagePrice2k(v float64) *GroupUpdate {
	_u.mutation.ResetImagePrice2k()
	_u.mutation.SetImagePrice2k(v)
	return _u
}

// SetNillableImagePrice2k sets the "image_price_2k" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableImagePrice2k(v *float64) *GroupUpdate {
	if v != nil {
		_u.SetImagePrice2k(*v)
	}
	return _u
}

// AddImagePrice2k adds value to the "image_price_2k" field.
func (_u *GroupUpdate) AddImagePrice2k(v float64) *GroupUpdate {
	_u.mutation.AddImagePrice2k(v)
	return _u
}

// ClearImagePrice2k clears the value of the "image_price_2k" field.
func (_u *GroupUpdate) ClearImagePrice2k() *GroupUpdate {
	_u.mutation.ClearImagePrice2k()
	return _u
}

// SetImagePrice4k sets the "image_price_4k" field.
func (_u *GroupUpdate) SetImagePrice4k(v float64) *GroupUpdate {
	_u.mutation.ResetImagePrice4k()
	_u.mutation.SetImagePrice4k(v)
	return _u
}

// SetNillableImagePrice4k sets the "image_price_4k" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableImagePrice4k(v *float64) *GroupUpdate {
	if v != nil {
		_u.SetImagePrice4k(*v)
	}
	return _u
}

// AddImagePrice4k adds value to the "image_price_4k" field.
func (_u *GroupUpdate) AddImagePrice4k(v float64) *GroupUpdate {
	_u.mutation.AddImagePrice4k(v)
	return _u
}

// ClearImagePrice4k clears the value of the "image_price_4k" field.
func (_u *GroupUpdate) ClearImagePrice4k() *GroupUpdate {
	_u.mutation.ClearImagePrice4k()
	return _u
}

// SetClaudeCodeOnly sets the "claude_code_only" field.
func (_u *GroupUpdate) SetClaudeCodeOnly(v bool) *GroupUpdate {
	_u.mutation.SetClaudeCodeOnly(v)
	return _u
}

// SetNillableClaudeCodeOnly sets the "claude_code_only" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableClaudeCodeOnly(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetClaudeCodeOnly(*v)
	}
	return _u
}

// SetFallbackGroupID sets the "fallback_group_id" field.
func (_u *GroupUpdate) SetFallbackGroupID(v int64) *GroupUpdate {
	_u.mutation.ResetFallbackGroupID()
	_u.mutation.SetFallbackGroupID(v)
	return _u
}

// SetNillableFallbackGroupID sets the "fallback_group_id" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableFallbackGroupID(v *int64) *GroupUpdate {
	if v != nil {
		_u.SetFallbackGroupID(*v)
	}
	return _u
}

// AddFallbackGroupID adds value to the "fallback_group_id" field.
func (_u *GroupUpdate) AddFallbackGroupID(v int64) *GroupUpdate {
	_u.mutation.AddFallbackGroupID(v)
	return _u
}

// ClearFallbackGroupID clears the value of the "fallback_group_id" field.
func (_u *GroupUpdate) ClearFallbackGroupID() *GroupUpdate {
	_u.mutation.ClearFallbackGroupID()
	return _u
}

// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func (_u *GroupUpdate) SetFallbackGroupIDOnInvalidRequest(v int64) *GroupUpdate {
	_u.mutation.ResetFallbackGroupIDOnInvalidRequest()
	_u.mutation.SetFallbackGroupIDOnInvalidRequest(v)
	return _u
}

// SetNillableFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableFallbackGroupIDOnInvalidRequest(v *int64) *GroupUpdate {
	if v != nil {
		_u.SetFallbackGroupIDOnInvalidRequest(*v)
	}
	return _u
}

// AddFallbackGroupIDOnInvalidRequest adds value to the "fallback_group_id_on_invalid_request" field.
func (_u *GroupUpdate) AddFallbackGroupIDOnInvalidRequest(v int64) *GroupUpdate {
	_u.mutation.AddFallbackGroupIDOnInvalidRequest(v)
	return _u
}

// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func (_u *GroupUpdate) ClearFallbackGroupIDOnInvalidRequest() *GroupUpdate {
	_u.mutation.ClearFallbackGroupIDOnInvalidRequest()
	return _u
}

// SetModelRouting sets the "model_routing" field.
func (_u *GroupUpdate) SetModelRouting(v map[string][]int64) *GroupUpdate {
	_u.mutation.SetModelRouting(v)
	return _u
}

// ClearModelRouting clears the value of the "model_routing" field.
func (_u *GroupUpdate) ClearModelRouting() *GroupUpdate {
	_u.mutation.ClearModelRouting()
	return _u
}

// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func (_u *GroupUpdate) SetModelRoutingEnabled(v bool) *GroupUpdate {
	_u.mutation.SetModelRoutingEnabled(v)
	return _u
}

// SetNillableModelRoutingEnabled sets the "model_routing_enabled" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableModelRoutingEnabled(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetModelRoutingEnabled(*v)
	}
	return _u
}

// SetMcpXMLInject sets the "mcp_xml_inject" field.
func (_u *GroupUpdate) SetMcpXMLInject(v bool) *GroupUpdate {
	_u.mutation.SetMcpXMLInject(v)
	return _u
}

// SetNillableMcpXMLInject sets the "mcp_xml_inject" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableMcpXMLInject(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetMcpXMLInject(*v)
	}
	return _u
}

// SetSupportedModelScopes sets the "supported_model_scopes" field.
func (_u *GroupUpdate) SetSupportedModelScopes(v []string) *GroupUpdate {
	_u.mutation.SetSupportedModelScopes(v)
	return _u
}

// AppendSupportedModelScopes appends value to the "supported_model_scopes" field.
func (_u *GroupUpdate) AppendSupportedModelScopes(v []string) *GroupUpdate {
	_u.mutation.AppendSupportedModelScopes(v)
	return _u
}

// SetSortOrder sets the "sort_order" field.
func (_u *GroupUpdate) SetSortOrder(v int) *GroupUpdate {
	_u.mutation.ResetSortOrder()
	_u.mutation.SetSortOrder(v)
	return _u
}

// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableSortOrder(v *int) *GroupUpdate {
	if v != nil {
		_u.SetSortOrder(*v)
	}
	return _u
}

// AddSortOrder adds value to the "sort_order" field.
func (_u *GroupUpdate) AddSortOrder(v int) *GroupUpdate {
	_u.mutation.AddSortOrder(v)
	return _u
}

// SetAllowMessagesDispatch sets the "allow_messages_dispatch" field.
func (_u *GroupUpdate) SetAllowMessagesDispatch(v bool) *GroupUpdate {
	_u.mutation.SetAllowMessagesDispatch(v)
	return _u
}

// SetNillableAllowMessagesDispatch sets the "allow_messages_dispatch" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableAllowMessagesDispatch(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetAllowMessagesDispatch(*v)
	}
	return _u
}

// SetRequireOauthOnly sets the "require_oauth_only" field.
func (_u *GroupUpdate) SetRequireOauthOnly(v bool) *GroupUpdate {
	_u.mutation.SetRequireOauthOnly(v)
	return _u
}

// SetNillableRequireOauthOnly sets the "require_oauth_only" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableRequireOauthOnly(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetRequireOauthOnly(*v)
	}
	return _u
}

// SetRequirePrivacySet sets the "require_privacy_set" field.
func (_u *GroupUpdate) SetRequirePrivacySet(v bool) *GroupUpdate {
	_u.mutation.SetRequirePrivacySet(v)
	return _u
}

// SetNillableRequirePrivacySet sets the "require_privacy_set" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableRequirePrivacySet(v *bool) *GroupUpdate {
	if v != nil {
		_u.SetRequirePrivacySet(*v)
	}
	return _u
}

// SetDefaultMappedModel sets the "default_mapped_model" field.
func (_u *GroupUpdate) SetDefaultMappedModel(v string) *GroupUpdate {
	_u.mutation.SetDefaultMappedModel(v)
	return _u
}

// SetNillableDefaultMappedModel sets the "default_mapped_model" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableDefaultMappedModel(v *string) *GroupUpdate {
	if v != nil {
		_u.SetDefaultMappedModel(*v)
	}
	return _u
}

// SetMessagesDispatchModelConfig sets the "messages_dispatch_model_config" field.
func (_u *GroupUpdate) SetMessagesDispatchModelConfig(v domain.OpenAIMessagesDispatchModelConfig) *GroupUpdate {
	_u.mutation.SetMessagesDispatchModelConfig(v)
	return _u
}

// SetNillableMessagesDispatchModelConfig sets the "messages_dispatch_model_config" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMessagesDispatchModelConfig) *GroupUpdate {
	if v != nil {
		_u.SetMessagesDispatchModelConfig(*v)
	}
	return _u
}

// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *GroupUpdate) AddAPIKeyIDs(ids ...int64) *GroupUpdate {
	_u.mutation.AddAPIKeyIDs(ids...)
	return _u
}

// AddAPIKeys adds the "api_keys" edges to the APIKey entity.
func (_u *GroupUpdate) AddAPIKeys(v ...*APIKey) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAPIKeyIDs(ids...)
}

// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
func (_u *GroupUpdate) AddRedeemCodeIDs(ids ...int64) *GroupUpdate {
	_u.mutation.AddRedeemCodeIDs(ids...)
	return _u
}

// AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
func (_u *GroupUpdate) AddRedeemCodes(v ...*RedeemCode) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddRedeemCodeIDs(ids...)
}

// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
func (_u *GroupUpdate) AddSubscriptionIDs(ids ...int64) *GroupUpdate {
	_u.mutation.AddSubscriptionIDs(ids...)
	return _u
}

// AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
func (_u *GroupUpdate) AddSubscriptions(v ...*UserSubscription) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSubscriptionIDs(ids...)
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *GroupUpdate) AddUsageLogIDs(ids ...int64) *GroupUpdate {
	_u.mutation.AddUsageLogIDs(ids...)
	return _u
}

// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdate) AddUsageLogs(v ...*UsageLog) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddUsageLogIDs(ids...)
}

// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *GroupUpdate) AddAccountIDs(ids ...int64) *GroupUpdate {
	_u.mutation.AddAccountIDs(ids...)
	return _u
}

// AddAccounts adds the "accounts" edges to the Account entity.
func (_u *GroupUpdate) AddAccounts(v ...*Account) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAccountIDs(ids...)
}

// AddAllowedUserIDs adds the "allowed_users" edge to the User entity by IDs.
func (_u *GroupUpdate) AddAllowedUserIDs(ids ...int64) *GroupUpdate {
	_u.mutation.AddAllowedUserIDs(ids...)
	return _u
}

// AddAllowedUsers adds the "allowed_users" edges to the User entity.
func (_u *GroupUpdate) AddAllowedUsers(v ...*User) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAllowedUserIDs(ids...)
}

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

// ClearAPIKeys clears all "api_keys" edges to the APIKey entity.
func (_u *GroupUpdate) ClearAPIKeys() *GroupUpdate {
	_u.mutation.ClearAPIKeys()
	return _u
}

// RemoveAPIKeyIDs removes the "api_keys" edge to APIKey entities by IDs.
func (_u *GroupUpdate) RemoveAPIKeyIDs(ids ...int64) *GroupUpdate {
	_u.mutation.RemoveAPIKeyIDs(ids...)
	return _u
}

// RemoveAPIKeys removes "api_keys" edges to APIKey entities.
func (_u *GroupUpdate) RemoveAPIKeys(v ...*APIKey) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAPIKeyIDs(ids...)
}

// ClearRedeemCodes clears all "redeem_codes" edges to the RedeemCode entity.
func (_u *GroupUpdate) ClearRedeemCodes() *GroupUpdate {
	_u.mutation.ClearRedeemCodes()
	return _u
}

// RemoveRedeemCodeIDs removes the "redeem_codes" edge to RedeemCode entities by IDs.
func (_u *GroupUpdate) RemoveRedeemCodeIDs(ids ...int64) *GroupUpdate {
	_u.mutation.RemoveRedeemCodeIDs(ids...)
	return _u
}

// RemoveRedeemCodes removes "redeem_codes" edges to RedeemCode entities.
func (_u *GroupUpdate) RemoveRedeemCodes(v ...*RedeemCode) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveRedeemCodeIDs(ids...)
}

// ClearSubscriptions clears all "subscriptions" edges to the UserSubscription entity.
func (_u *GroupUpdate) ClearSubscriptions() *GroupUpdate {
	_u.mutation.ClearSubscriptions()
	return _u
}

// RemoveSubscriptionIDs removes the "subscriptions" edge to UserSubscription entities by IDs.
func (_u *GroupUpdate) RemoveSubscriptionIDs(ids ...int64) *GroupUpdate {
	_u.mutation.RemoveSubscriptionIDs(ids...)
	return _u
}

// RemoveSubscriptions removes "subscriptions" edges to UserSubscription entities.
func (_u *GroupUpdate) RemoveSubscriptions(v ...*UserSubscription) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSubscriptionIDs(ids...)
}

// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdate) ClearUsageLogs() *GroupUpdate {
	_u.mutation.ClearUsageLogs()
	return _u
}

// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *GroupUpdate) RemoveUsageLogIDs(ids ...int64) *GroupUpdate {
	_u.mutation.RemoveUsageLogIDs(ids...)
	return _u
}

// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *GroupUpdate) RemoveUsageLogs(v ...*UsageLog) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveUsageLogIDs(ids...)
}

// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *GroupUpdate) ClearAccounts() *GroupUpdate {
	_u.mutation.ClearAccounts()
	return _u
}

// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
func (_u *GroupUpdate) RemoveAccountIDs(ids ...int64) *GroupUpdate {
	_u.mutation.RemoveAccountIDs(ids...)
	return _u
}

// RemoveAccounts removes "accounts" edges to Account entities.
func (_u *GroupUpdate) RemoveAccounts(v ...*Account) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAccountIDs(ids...)
}

// ClearAllowedUsers clears all "allowed_users" edges to the User entity.
func (_u *GroupUpdate) ClearAllowedUsers() *GroupUpdate {
	_u.mutation.ClearAllowedUsers()
	return _u
}

// RemoveAllowedUserIDs removes the "allowed_users" edge to User entities by IDs.
func (_u *GroupUpdate) RemoveAllowedUserIDs(ids ...int64) *GroupUpdate {
	_u.mutation.RemoveAllowedUserIDs(ids...)
	return _u
}

// RemoveAllowedUsers removes "allowed_users" edges to User entities.
func (_u *GroupUpdate) RemoveAllowedUsers(v ...*User) *GroupUpdate {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAllowedUserIDs(ids...)
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *GroupUpdate) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := group.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := group.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Group.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Platform(); ok {
		if err := group.PlatformValidator(v); err != nil {
			return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Group.platform": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SubscriptionType(); ok {
		if err := group.SubscriptionTypeValidator(v); err != nil {
			return &ValidationError{Name: "subscription_type", err: fmt.Errorf(`ent: validator failed for field "Group.subscription_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.DefaultMappedModel(); ok {
		if err := group.DefaultMappedModelValidator(v); err != nil {
			return &ValidationError{Name: "default_mapped_model", err: fmt.Errorf(`ent: validator failed for field "Group.default_mapped_model": %w`, err)}
		}
	}
	return nil
}

func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.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.UpdatedAt(); ok {
		_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(group.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(group.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(group.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(group.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(group.FieldDescription, field.TypeString)
	}
	if value, ok := _u.mutation.RateMultiplier(); ok {
		_spec.SetField(group.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRateMultiplier(); ok {
		_spec.AddField(group.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.IsExclusive(); ok {
		_spec.SetField(group.FieldIsExclusive, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(group.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Platform(); ok {
		_spec.SetField(group.FieldPlatform, field.TypeString, value)
	}
	if value, ok := _u.mutation.SubscriptionType(); ok {
		_spec.SetField(group.FieldSubscriptionType, field.TypeString, value)
	}
	if value, ok := _u.mutation.DailyLimitUsd(); ok {
		_spec.SetField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
		_spec.AddField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
	}
	if _u.mutation.DailyLimitUsdCleared() {
		_spec.ClearField(group.FieldDailyLimitUsd, field.TypeFloat64)
	}
	if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
		_spec.SetField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
		_spec.AddField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
	}
	if _u.mutation.WeeklyLimitUsdCleared() {
		_spec.ClearField(group.FieldWeeklyLimitUsd, field.TypeFloat64)
	}
	if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
		_spec.SetField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
		_spec.AddField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
	}
	if _u.mutation.MonthlyLimitUsdCleared() {
		_spec.ClearField(group.FieldMonthlyLimitUsd, field.TypeFloat64)
	}
	if value, ok := _u.mutation.DefaultValidityDays(); ok {
		_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDefaultValidityDays(); ok {
		_spec.AddField(group.FieldDefaultValidityDays, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ImagePrice1k(); ok {
		_spec.SetField(group.FieldImagePrice1k, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedImagePrice1k(); ok {
		_spec.AddField(group.FieldImagePrice1k, field.TypeFloat64, value)
	}
	if _u.mutation.ImagePrice1kCleared() {
		_spec.ClearField(group.FieldImagePrice1k, field.TypeFloat64)
	}
	if value, ok := _u.mutation.ImagePrice2k(); ok {
		_spec.SetField(group.FieldImagePrice2k, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedImagePrice2k(); ok {
		_spec.AddField(group.FieldImagePrice2k, field.TypeFloat64, value)
	}
	if _u.mutation.ImagePrice2kCleared() {
		_spec.ClearField(group.FieldImagePrice2k, field.TypeFloat64)
	}
	if value, ok := _u.mutation.ImagePrice4k(); ok {
		_spec.SetField(group.FieldImagePrice4k, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedImagePrice4k(); ok {
		_spec.AddField(group.FieldImagePrice4k, field.TypeFloat64, value)
	}
	if _u.mutation.ImagePrice4kCleared() {
		_spec.ClearField(group.FieldImagePrice4k, field.TypeFloat64)
	}
	if value, ok := _u.mutation.ClaudeCodeOnly(); ok {
		_spec.SetField(group.FieldClaudeCodeOnly, field.TypeBool, value)
	}
	if value, ok := _u.mutation.FallbackGroupID(); ok {
		_spec.SetField(group.FieldFallbackGroupID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedFallbackGroupID(); ok {
		_spec.AddField(group.FieldFallbackGroupID, field.TypeInt64, value)
	}
	if _u.mutation.FallbackGroupIDCleared() {
		_spec.ClearField(group.FieldFallbackGroupID, field.TypeInt64)
	}
	if value, ok := _u.mutation.FallbackGroupIDOnInvalidRequest(); ok {
		_spec.SetField(group.FieldFallbackGroupIDOnInvalidRequest, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedFallbackGroupIDOnInvalidRequest(); ok {
		_spec.AddField(group.FieldFallbackGroupIDOnInvalidRequest, field.TypeInt64, value)
	}
	if _u.mutation.FallbackGroupIDOnInvalidRequestCleared() {
		_spec.ClearField(group.FieldFallbackGroupIDOnInvalidRequest, field.TypeInt64)
	}
	if value, ok := _u.mutation.ModelRouting(); ok {
		_spec.SetField(group.FieldModelRouting, field.TypeJSON, value)
	}
	if _u.mutation.ModelRoutingCleared() {
		_spec.ClearField(group.FieldModelRouting, field.TypeJSON)
	}
	if value, ok := _u.mutation.ModelRoutingEnabled(); ok {
		_spec.SetField(group.FieldModelRoutingEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.McpXMLInject(); ok {
		_spec.SetField(group.FieldMcpXMLInject, field.TypeBool, value)
	}
	if value, ok := _u.mutation.SupportedModelScopes(); ok {
		_spec.SetField(group.FieldSupportedModelScopes, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedSupportedModelScopes(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, group.FieldSupportedModelScopes, value)
		})
	}
	if value, ok := _u.mutation.SortOrder(); ok {
		_spec.SetField(group.FieldSortOrder, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedSortOrder(); ok {
		_spec.AddField(group.FieldSortOrder, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AllowMessagesDispatch(); ok {
		_spec.SetField(group.FieldAllowMessagesDispatch, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RequireOauthOnly(); ok {
		_spec.SetField(group.FieldRequireOauthOnly, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RequirePrivacySet(); ok {
		_spec.SetField(group.FieldRequirePrivacySet, field.TypeBool, value)
	}
	if value, ok := _u.mutation.DefaultMappedModel(); ok {
		_spec.SetField(group.FieldDefaultMappedModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.MessagesDispatchModelConfig(); ok {
		_spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value)
	}
	if _u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.APIKeysTable,
			Columns: []string{group.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAPIKeysIDs(); len(nodes) > 0 && !_u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.APIKeysTable,
			Columns: []string{group.APIKeysColumn},
			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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.APIKeysIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.APIKeysTable,
			Columns: []string{group.APIKeysColumn},
			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.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.RedeemCodesTable,
			Columns: []string{group.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedRedeemCodesIDs(); len(nodes) > 0 && !_u.mutation.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.RedeemCodesTable,
			Columns: []string{group.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RedeemCodesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.RedeemCodesTable,
			Columns: []string{group.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.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.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.SubscriptionsTable,
			Columns: []string{group.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.SubscriptionsTable,
			Columns: []string{group.SubscriptionsColumn},
			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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SubscriptionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.SubscriptionsTable,
			Columns: []string{group.SubscriptionsColumn},
			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 _u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.UsageLogsTable,
			Columns: []string{group.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.UsageLogsTable,
			Columns: []string{group.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.UsageLogsTable,
			Columns: []string{group.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.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.AccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AccountsTable,
			Columns: group.AccountsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AccountsTable,
			Columns: group.AccountsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AccountsTable,
			Columns: group.AccountsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.AllowedUsersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AllowedUsersTable,
			Columns: group.AllowedUsersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAllowedUsersIDs(); len(nodes) > 0 && !_u.mutation.AllowedUsersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AllowedUsersTable,
			Columns: group.AllowedUsersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AllowedUsersIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AllowedUsersTable,
			Columns: group.AllowedUsersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_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{group.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// GroupUpdateOne is the builder for updating a single Group entity.
type GroupUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *GroupMutation
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *GroupUpdateOne) SetUpdatedAt(v time.Time) *GroupUpdateOne {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetDeletedAt sets the "deleted_at" field.
func (_u *GroupUpdateOne) SetDeletedAt(v time.Time) *GroupUpdateOne {
	_u.mutation.SetDeletedAt(v)
	return _u
}

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

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

// SetName sets the "name" field.
func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne {
	_u.mutation.SetName(v)
	return _u
}

// SetNillableName sets the "name" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableName(v *string) *GroupUpdateOne {
	if v != nil {
		_u.SetName(*v)
	}
	return _u
}

// SetDescription sets the "description" field.
func (_u *GroupUpdateOne) SetDescription(v string) *GroupUpdateOne {
	_u.mutation.SetDescription(v)
	return _u
}

// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableDescription(v *string) *GroupUpdateOne {
	if v != nil {
		_u.SetDescription(*v)
	}
	return _u
}

// ClearDescription clears the value of the "description" field.
func (_u *GroupUpdateOne) ClearDescription() *GroupUpdateOne {
	_u.mutation.ClearDescription()
	return _u
}

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

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

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

// SetIsExclusive sets the "is_exclusive" field.
func (_u *GroupUpdateOne) SetIsExclusive(v bool) *GroupUpdateOne {
	_u.mutation.SetIsExclusive(v)
	return _u
}

// SetNillableIsExclusive sets the "is_exclusive" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableIsExclusive(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetIsExclusive(*v)
	}
	return _u
}

// SetStatus sets the "status" field.
func (_u *GroupUpdateOne) SetStatus(v string) *GroupUpdateOne {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableStatus(v *string) *GroupUpdateOne {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetPlatform sets the "platform" field.
func (_u *GroupUpdateOne) SetPlatform(v string) *GroupUpdateOne {
	_u.mutation.SetPlatform(v)
	return _u
}

// SetNillablePlatform sets the "platform" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillablePlatform(v *string) *GroupUpdateOne {
	if v != nil {
		_u.SetPlatform(*v)
	}
	return _u
}

// SetSubscriptionType sets the "subscription_type" field.
func (_u *GroupUpdateOne) SetSubscriptionType(v string) *GroupUpdateOne {
	_u.mutation.SetSubscriptionType(v)
	return _u
}

// SetNillableSubscriptionType sets the "subscription_type" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableSubscriptionType(v *string) *GroupUpdateOne {
	if v != nil {
		_u.SetSubscriptionType(*v)
	}
	return _u
}

// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (_u *GroupUpdateOne) SetDailyLimitUsd(v float64) *GroupUpdateOne {
	_u.mutation.ResetDailyLimitUsd()
	_u.mutation.SetDailyLimitUsd(v)
	return _u
}

// SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableDailyLimitUsd(v *float64) *GroupUpdateOne {
	if v != nil {
		_u.SetDailyLimitUsd(*v)
	}
	return _u
}

// AddDailyLimitUsd adds value to the "daily_limit_usd" field.
func (_u *GroupUpdateOne) AddDailyLimitUsd(v float64) *GroupUpdateOne {
	_u.mutation.AddDailyLimitUsd(v)
	return _u
}

// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
func (_u *GroupUpdateOne) ClearDailyLimitUsd() *GroupUpdateOne {
	_u.mutation.ClearDailyLimitUsd()
	return _u
}

// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (_u *GroupUpdateOne) SetWeeklyLimitUsd(v float64) *GroupUpdateOne {
	_u.mutation.ResetWeeklyLimitUsd()
	_u.mutation.SetWeeklyLimitUsd(v)
	return _u
}

// SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableWeeklyLimitUsd(v *float64) *GroupUpdateOne {
	if v != nil {
		_u.SetWeeklyLimitUsd(*v)
	}
	return _u
}

// AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
func (_u *GroupUpdateOne) AddWeeklyLimitUsd(v float64) *GroupUpdateOne {
	_u.mutation.AddWeeklyLimitUsd(v)
	return _u
}

// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
func (_u *GroupUpdateOne) ClearWeeklyLimitUsd() *GroupUpdateOne {
	_u.mutation.ClearWeeklyLimitUsd()
	return _u
}

// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (_u *GroupUpdateOne) SetMonthlyLimitUsd(v float64) *GroupUpdateOne {
	_u.mutation.ResetMonthlyLimitUsd()
	_u.mutation.SetMonthlyLimitUsd(v)
	return _u
}

// SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableMonthlyLimitUsd(v *float64) *GroupUpdateOne {
	if v != nil {
		_u.SetMonthlyLimitUsd(*v)
	}
	return _u
}

// AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
func (_u *GroupUpdateOne) AddMonthlyLimitUsd(v float64) *GroupUpdateOne {
	_u.mutation.AddMonthlyLimitUsd(v)
	return _u
}

// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
func (_u *GroupUpdateOne) ClearMonthlyLimitUsd() *GroupUpdateOne {
	_u.mutation.ClearMonthlyLimitUsd()
	return _u
}

// SetDefaultValidityDays sets the "default_validity_days" field.
func (_u *GroupUpdateOne) SetDefaultValidityDays(v int) *GroupUpdateOne {
	_u.mutation.ResetDefaultValidityDays()
	_u.mutation.SetDefaultValidityDays(v)
	return _u
}

// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableDefaultValidityDays(v *int) *GroupUpdateOne {
	if v != nil {
		_u.SetDefaultValidityDays(*v)
	}
	return _u
}

// AddDefaultValidityDays adds value to the "default_validity_days" field.
func (_u *GroupUpdateOne) AddDefaultValidityDays(v int) *GroupUpdateOne {
	_u.mutation.AddDefaultValidityDays(v)
	return _u
}

// SetImagePrice1k sets the "image_price_1k" field.
func (_u *GroupUpdateOne) SetImagePrice1k(v float64) *GroupUpdateOne {
	_u.mutation.ResetImagePrice1k()
	_u.mutation.SetImagePrice1k(v)
	return _u
}

// SetNillableImagePrice1k sets the "image_price_1k" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableImagePrice1k(v *float64) *GroupUpdateOne {
	if v != nil {
		_u.SetImagePrice1k(*v)
	}
	return _u
}

// AddImagePrice1k adds value to the "image_price_1k" field.
func (_u *GroupUpdateOne) AddImagePrice1k(v float64) *GroupUpdateOne {
	_u.mutation.AddImagePrice1k(v)
	return _u
}

// ClearImagePrice1k clears the value of the "image_price_1k" field.
func (_u *GroupUpdateOne) ClearImagePrice1k() *GroupUpdateOne {
	_u.mutation.ClearImagePrice1k()
	return _u
}

// SetImagePrice2k sets the "image_price_2k" field.
func (_u *GroupUpdateOne) SetImagePrice2k(v float64) *GroupUpdateOne {
	_u.mutation.ResetImagePrice2k()
	_u.mutation.SetImagePrice2k(v)
	return _u
}

// SetNillableImagePrice2k sets the "image_price_2k" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableImagePrice2k(v *float64) *GroupUpdateOne {
	if v != nil {
		_u.SetImagePrice2k(*v)
	}
	return _u
}

// AddImagePrice2k adds value to the "image_price_2k" field.
func (_u *GroupUpdateOne) AddImagePrice2k(v float64) *GroupUpdateOne {
	_u.mutation.AddImagePrice2k(v)
	return _u
}

// ClearImagePrice2k clears the value of the "image_price_2k" field.
func (_u *GroupUpdateOne) ClearImagePrice2k() *GroupUpdateOne {
	_u.mutation.ClearImagePrice2k()
	return _u
}

// SetImagePrice4k sets the "image_price_4k" field.
func (_u *GroupUpdateOne) SetImagePrice4k(v float64) *GroupUpdateOne {
	_u.mutation.ResetImagePrice4k()
	_u.mutation.SetImagePrice4k(v)
	return _u
}

// SetNillableImagePrice4k sets the "image_price_4k" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableImagePrice4k(v *float64) *GroupUpdateOne {
	if v != nil {
		_u.SetImagePrice4k(*v)
	}
	return _u
}

// AddImagePrice4k adds value to the "image_price_4k" field.
func (_u *GroupUpdateOne) AddImagePrice4k(v float64) *GroupUpdateOne {
	_u.mutation.AddImagePrice4k(v)
	return _u
}

// ClearImagePrice4k clears the value of the "image_price_4k" field.
func (_u *GroupUpdateOne) ClearImagePrice4k() *GroupUpdateOne {
	_u.mutation.ClearImagePrice4k()
	return _u
}

// SetClaudeCodeOnly sets the "claude_code_only" field.
func (_u *GroupUpdateOne) SetClaudeCodeOnly(v bool) *GroupUpdateOne {
	_u.mutation.SetClaudeCodeOnly(v)
	return _u
}

// SetNillableClaudeCodeOnly sets the "claude_code_only" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableClaudeCodeOnly(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetClaudeCodeOnly(*v)
	}
	return _u
}

// SetFallbackGroupID sets the "fallback_group_id" field.
func (_u *GroupUpdateOne) SetFallbackGroupID(v int64) *GroupUpdateOne {
	_u.mutation.ResetFallbackGroupID()
	_u.mutation.SetFallbackGroupID(v)
	return _u
}

// SetNillableFallbackGroupID sets the "fallback_group_id" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableFallbackGroupID(v *int64) *GroupUpdateOne {
	if v != nil {
		_u.SetFallbackGroupID(*v)
	}
	return _u
}

// AddFallbackGroupID adds value to the "fallback_group_id" field.
func (_u *GroupUpdateOne) AddFallbackGroupID(v int64) *GroupUpdateOne {
	_u.mutation.AddFallbackGroupID(v)
	return _u
}

// ClearFallbackGroupID clears the value of the "fallback_group_id" field.
func (_u *GroupUpdateOne) ClearFallbackGroupID() *GroupUpdateOne {
	_u.mutation.ClearFallbackGroupID()
	return _u
}

// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func (_u *GroupUpdateOne) SetFallbackGroupIDOnInvalidRequest(v int64) *GroupUpdateOne {
	_u.mutation.ResetFallbackGroupIDOnInvalidRequest()
	_u.mutation.SetFallbackGroupIDOnInvalidRequest(v)
	return _u
}

// SetNillableFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableFallbackGroupIDOnInvalidRequest(v *int64) *GroupUpdateOne {
	if v != nil {
		_u.SetFallbackGroupIDOnInvalidRequest(*v)
	}
	return _u
}

// AddFallbackGroupIDOnInvalidRequest adds value to the "fallback_group_id_on_invalid_request" field.
func (_u *GroupUpdateOne) AddFallbackGroupIDOnInvalidRequest(v int64) *GroupUpdateOne {
	_u.mutation.AddFallbackGroupIDOnInvalidRequest(v)
	return _u
}

// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func (_u *GroupUpdateOne) ClearFallbackGroupIDOnInvalidRequest() *GroupUpdateOne {
	_u.mutation.ClearFallbackGroupIDOnInvalidRequest()
	return _u
}

// SetModelRouting sets the "model_routing" field.
func (_u *GroupUpdateOne) SetModelRouting(v map[string][]int64) *GroupUpdateOne {
	_u.mutation.SetModelRouting(v)
	return _u
}

// ClearModelRouting clears the value of the "model_routing" field.
func (_u *GroupUpdateOne) ClearModelRouting() *GroupUpdateOne {
	_u.mutation.ClearModelRouting()
	return _u
}

// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func (_u *GroupUpdateOne) SetModelRoutingEnabled(v bool) *GroupUpdateOne {
	_u.mutation.SetModelRoutingEnabled(v)
	return _u
}

// SetNillableModelRoutingEnabled sets the "model_routing_enabled" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableModelRoutingEnabled(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetModelRoutingEnabled(*v)
	}
	return _u
}

// SetMcpXMLInject sets the "mcp_xml_inject" field.
func (_u *GroupUpdateOne) SetMcpXMLInject(v bool) *GroupUpdateOne {
	_u.mutation.SetMcpXMLInject(v)
	return _u
}

// SetNillableMcpXMLInject sets the "mcp_xml_inject" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableMcpXMLInject(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetMcpXMLInject(*v)
	}
	return _u
}

// SetSupportedModelScopes sets the "supported_model_scopes" field.
func (_u *GroupUpdateOne) SetSupportedModelScopes(v []string) *GroupUpdateOne {
	_u.mutation.SetSupportedModelScopes(v)
	return _u
}

// AppendSupportedModelScopes appends value to the "supported_model_scopes" field.
func (_u *GroupUpdateOne) AppendSupportedModelScopes(v []string) *GroupUpdateOne {
	_u.mutation.AppendSupportedModelScopes(v)
	return _u
}

// SetSortOrder sets the "sort_order" field.
func (_u *GroupUpdateOne) SetSortOrder(v int) *GroupUpdateOne {
	_u.mutation.ResetSortOrder()
	_u.mutation.SetSortOrder(v)
	return _u
}

// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableSortOrder(v *int) *GroupUpdateOne {
	if v != nil {
		_u.SetSortOrder(*v)
	}
	return _u
}

// AddSortOrder adds value to the "sort_order" field.
func (_u *GroupUpdateOne) AddSortOrder(v int) *GroupUpdateOne {
	_u.mutation.AddSortOrder(v)
	return _u
}

// SetAllowMessagesDispatch sets the "allow_messages_dispatch" field.
func (_u *GroupUpdateOne) SetAllowMessagesDispatch(v bool) *GroupUpdateOne {
	_u.mutation.SetAllowMessagesDispatch(v)
	return _u
}

// SetNillableAllowMessagesDispatch sets the "allow_messages_dispatch" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableAllowMessagesDispatch(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetAllowMessagesDispatch(*v)
	}
	return _u
}

// SetRequireOauthOnly sets the "require_oauth_only" field.
func (_u *GroupUpdateOne) SetRequireOauthOnly(v bool) *GroupUpdateOne {
	_u.mutation.SetRequireOauthOnly(v)
	return _u
}

// SetNillableRequireOauthOnly sets the "require_oauth_only" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableRequireOauthOnly(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetRequireOauthOnly(*v)
	}
	return _u
}

// SetRequirePrivacySet sets the "require_privacy_set" field.
func (_u *GroupUpdateOne) SetRequirePrivacySet(v bool) *GroupUpdateOne {
	_u.mutation.SetRequirePrivacySet(v)
	return _u
}

// SetNillableRequirePrivacySet sets the "require_privacy_set" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableRequirePrivacySet(v *bool) *GroupUpdateOne {
	if v != nil {
		_u.SetRequirePrivacySet(*v)
	}
	return _u
}

// SetDefaultMappedModel sets the "default_mapped_model" field.
func (_u *GroupUpdateOne) SetDefaultMappedModel(v string) *GroupUpdateOne {
	_u.mutation.SetDefaultMappedModel(v)
	return _u
}

// SetNillableDefaultMappedModel sets the "default_mapped_model" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableDefaultMappedModel(v *string) *GroupUpdateOne {
	if v != nil {
		_u.SetDefaultMappedModel(*v)
	}
	return _u
}

// SetMessagesDispatchModelConfig sets the "messages_dispatch_model_config" field.
func (_u *GroupUpdateOne) SetMessagesDispatchModelConfig(v domain.OpenAIMessagesDispatchModelConfig) *GroupUpdateOne {
	_u.mutation.SetMessagesDispatchModelConfig(v)
	return _u
}

// SetNillableMessagesDispatchModelConfig sets the "messages_dispatch_model_config" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMessagesDispatchModelConfig) *GroupUpdateOne {
	if v != nil {
		_u.SetMessagesDispatchModelConfig(*v)
	}
	return _u
}

// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *GroupUpdateOne) AddAPIKeyIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.AddAPIKeyIDs(ids...)
	return _u
}

// AddAPIKeys adds the "api_keys" edges to the APIKey entity.
func (_u *GroupUpdateOne) AddAPIKeys(v ...*APIKey) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAPIKeyIDs(ids...)
}

// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
func (_u *GroupUpdateOne) AddRedeemCodeIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.AddRedeemCodeIDs(ids...)
	return _u
}

// AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
func (_u *GroupUpdateOne) AddRedeemCodes(v ...*RedeemCode) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddRedeemCodeIDs(ids...)
}

// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
func (_u *GroupUpdateOne) AddSubscriptionIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.AddSubscriptionIDs(ids...)
	return _u
}

// AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
func (_u *GroupUpdateOne) AddSubscriptions(v ...*UserSubscription) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddSubscriptionIDs(ids...)
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *GroupUpdateOne) AddUsageLogIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.AddUsageLogIDs(ids...)
	return _u
}

// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdateOne) AddUsageLogs(v ...*UsageLog) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddUsageLogIDs(ids...)
}

// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *GroupUpdateOne) AddAccountIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.AddAccountIDs(ids...)
	return _u
}

// AddAccounts adds the "accounts" edges to the Account entity.
func (_u *GroupUpdateOne) AddAccounts(v ...*Account) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAccountIDs(ids...)
}

// AddAllowedUserIDs adds the "allowed_users" edge to the User entity by IDs.
func (_u *GroupUpdateOne) AddAllowedUserIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.AddAllowedUserIDs(ids...)
	return _u
}

// AddAllowedUsers adds the "allowed_users" edges to the User entity.
func (_u *GroupUpdateOne) AddAllowedUsers(v ...*User) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.AddAllowedUserIDs(ids...)
}

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

// ClearAPIKeys clears all "api_keys" edges to the APIKey entity.
func (_u *GroupUpdateOne) ClearAPIKeys() *GroupUpdateOne {
	_u.mutation.ClearAPIKeys()
	return _u
}

// RemoveAPIKeyIDs removes the "api_keys" edge to APIKey entities by IDs.
func (_u *GroupUpdateOne) RemoveAPIKeyIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.RemoveAPIKeyIDs(ids...)
	return _u
}

// RemoveAPIKeys removes "api_keys" edges to APIKey entities.
func (_u *GroupUpdateOne) RemoveAPIKeys(v ...*APIKey) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAPIKeyIDs(ids...)
}

// ClearRedeemCodes clears all "redeem_codes" edges to the RedeemCode entity.
func (_u *GroupUpdateOne) ClearRedeemCodes() *GroupUpdateOne {
	_u.mutation.ClearRedeemCodes()
	return _u
}

// RemoveRedeemCodeIDs removes the "redeem_codes" edge to RedeemCode entities by IDs.
func (_u *GroupUpdateOne) RemoveRedeemCodeIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.RemoveRedeemCodeIDs(ids...)
	return _u
}

// RemoveRedeemCodes removes "redeem_codes" edges to RedeemCode entities.
func (_u *GroupUpdateOne) RemoveRedeemCodes(v ...*RedeemCode) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveRedeemCodeIDs(ids...)
}

// ClearSubscriptions clears all "subscriptions" edges to the UserSubscription entity.
func (_u *GroupUpdateOne) ClearSubscriptions() *GroupUpdateOne {
	_u.mutation.ClearSubscriptions()
	return _u
}

// RemoveSubscriptionIDs removes the "subscriptions" edge to UserSubscription entities by IDs.
func (_u *GroupUpdateOne) RemoveSubscriptionIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.RemoveSubscriptionIDs(ids...)
	return _u
}

// RemoveSubscriptions removes "subscriptions" edges to UserSubscription entities.
func (_u *GroupUpdateOne) RemoveSubscriptions(v ...*UserSubscription) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveSubscriptionIDs(ids...)
}

// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdateOne) ClearUsageLogs() *GroupUpdateOne {
	_u.mutation.ClearUsageLogs()
	return _u
}

// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *GroupUpdateOne) RemoveUsageLogIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.RemoveUsageLogIDs(ids...)
	return _u
}

// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *GroupUpdateOne) RemoveUsageLogs(v ...*UsageLog) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveUsageLogIDs(ids...)
}

// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *GroupUpdateOne) ClearAccounts() *GroupUpdateOne {
	_u.mutation.ClearAccounts()
	return _u
}

// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
func (_u *GroupUpdateOne) RemoveAccountIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.RemoveAccountIDs(ids...)
	return _u
}

// RemoveAccounts removes "accounts" edges to Account entities.
func (_u *GroupUpdateOne) RemoveAccounts(v ...*Account) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAccountIDs(ids...)
}

// ClearAllowedUsers clears all "allowed_users" edges to the User entity.
func (_u *GroupUpdateOne) ClearAllowedUsers() *GroupUpdateOne {
	_u.mutation.ClearAllowedUsers()
	return _u
}

// RemoveAllowedUserIDs removes the "allowed_users" edge to User entities by IDs.
func (_u *GroupUpdateOne) RemoveAllowedUserIDs(ids ...int64) *GroupUpdateOne {
	_u.mutation.RemoveAllowedUserIDs(ids...)
	return _u
}

// RemoveAllowedUsers removes "allowed_users" edges to User entities.
func (_u *GroupUpdateOne) RemoveAllowedUsers(v ...*User) *GroupUpdateOne {
	ids := make([]int64, len(v))
	for i := range v {
		ids[i] = v[i].ID
	}
	return _u.RemoveAllowedUserIDs(ids...)
}

// Where appends a list predicates to the GroupUpdate builder.
func (_u *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne {
	_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 *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (_u *GroupUpdateOne) check() error {
	if v, ok := _u.mutation.Name(); ok {
		if err := group.NameValidator(v); err != nil {
			return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := group.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Group.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Platform(); ok {
		if err := group.PlatformValidator(v); err != nil {
			return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Group.platform": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SubscriptionType(); ok {
		if err := group.SubscriptionTypeValidator(v); err != nil {
			return &ValidationError{Name: "subscription_type", err: fmt.Errorf(`ent: validator failed for field "Group.subscription_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.DefaultMappedModel(); ok {
		if err := group.DefaultMappedModelValidator(v); err != nil {
			return &ValidationError{Name: "default_mapped_model", err: fmt.Errorf(`ent: validator failed for field "Group.default_mapped_model": %w`, err)}
		}
	}
	return nil
}

func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Group.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, group.FieldID)
		for _, f := range fields {
			if !group.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != group.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.UpdatedAt(); ok {
		_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.DeletedAt(); ok {
		_spec.SetField(group.FieldDeletedAt, field.TypeTime, value)
	}
	if _u.mutation.DeletedAtCleared() {
		_spec.ClearField(group.FieldDeletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.Name(); ok {
		_spec.SetField(group.FieldName, field.TypeString, value)
	}
	if value, ok := _u.mutation.Description(); ok {
		_spec.SetField(group.FieldDescription, field.TypeString, value)
	}
	if _u.mutation.DescriptionCleared() {
		_spec.ClearField(group.FieldDescription, field.TypeString)
	}
	if value, ok := _u.mutation.RateMultiplier(); ok {
		_spec.SetField(group.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRateMultiplier(); ok {
		_spec.AddField(group.FieldRateMultiplier, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.IsExclusive(); ok {
		_spec.SetField(group.FieldIsExclusive, field.TypeBool, value)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(group.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.Platform(); ok {
		_spec.SetField(group.FieldPlatform, field.TypeString, value)
	}
	if value, ok := _u.mutation.SubscriptionType(); ok {
		_spec.SetField(group.FieldSubscriptionType, field.TypeString, value)
	}
	if value, ok := _u.mutation.DailyLimitUsd(); ok {
		_spec.SetField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
		_spec.AddField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
	}
	if _u.mutation.DailyLimitUsdCleared() {
		_spec.ClearField(group.FieldDailyLimitUsd, field.TypeFloat64)
	}
	if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
		_spec.SetField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
		_spec.AddField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
	}
	if _u.mutation.WeeklyLimitUsdCleared() {
		_spec.ClearField(group.FieldWeeklyLimitUsd, field.TypeFloat64)
	}
	if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
		_spec.SetField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
		_spec.AddField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
	}
	if _u.mutation.MonthlyLimitUsdCleared() {
		_spec.ClearField(group.FieldMonthlyLimitUsd, field.TypeFloat64)
	}
	if value, ok := _u.mutation.DefaultValidityDays(); ok {
		_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedDefaultValidityDays(); ok {
		_spec.AddField(group.FieldDefaultValidityDays, field.TypeInt, value)
	}
	if value, ok := _u.mutation.ImagePrice1k(); ok {
		_spec.SetField(group.FieldImagePrice1k, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedImagePrice1k(); ok {
		_spec.AddField(group.FieldImagePrice1k, field.TypeFloat64, value)
	}
	if _u.mutation.ImagePrice1kCleared() {
		_spec.ClearField(group.FieldImagePrice1k, field.TypeFloat64)
	}
	if value, ok := _u.mutation.ImagePrice2k(); ok {
		_spec.SetField(group.FieldImagePrice2k, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedImagePrice2k(); ok {
		_spec.AddField(group.FieldImagePrice2k, field.TypeFloat64, value)
	}
	if _u.mutation.ImagePrice2kCleared() {
		_spec.ClearField(group.FieldImagePrice2k, field.TypeFloat64)
	}
	if value, ok := _u.mutation.ImagePrice4k(); ok {
		_spec.SetField(group.FieldImagePrice4k, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedImagePrice4k(); ok {
		_spec.AddField(group.FieldImagePrice4k, field.TypeFloat64, value)
	}
	if _u.mutation.ImagePrice4kCleared() {
		_spec.ClearField(group.FieldImagePrice4k, field.TypeFloat64)
	}
	if value, ok := _u.mutation.ClaudeCodeOnly(); ok {
		_spec.SetField(group.FieldClaudeCodeOnly, field.TypeBool, value)
	}
	if value, ok := _u.mutation.FallbackGroupID(); ok {
		_spec.SetField(group.FieldFallbackGroupID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedFallbackGroupID(); ok {
		_spec.AddField(group.FieldFallbackGroupID, field.TypeInt64, value)
	}
	if _u.mutation.FallbackGroupIDCleared() {
		_spec.ClearField(group.FieldFallbackGroupID, field.TypeInt64)
	}
	if value, ok := _u.mutation.FallbackGroupIDOnInvalidRequest(); ok {
		_spec.SetField(group.FieldFallbackGroupIDOnInvalidRequest, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedFallbackGroupIDOnInvalidRequest(); ok {
		_spec.AddField(group.FieldFallbackGroupIDOnInvalidRequest, field.TypeInt64, value)
	}
	if _u.mutation.FallbackGroupIDOnInvalidRequestCleared() {
		_spec.ClearField(group.FieldFallbackGroupIDOnInvalidRequest, field.TypeInt64)
	}
	if value, ok := _u.mutation.ModelRouting(); ok {
		_spec.SetField(group.FieldModelRouting, field.TypeJSON, value)
	}
	if _u.mutation.ModelRoutingCleared() {
		_spec.ClearField(group.FieldModelRouting, field.TypeJSON)
	}
	if value, ok := _u.mutation.ModelRoutingEnabled(); ok {
		_spec.SetField(group.FieldModelRoutingEnabled, field.TypeBool, value)
	}
	if value, ok := _u.mutation.McpXMLInject(); ok {
		_spec.SetField(group.FieldMcpXMLInject, field.TypeBool, value)
	}
	if value, ok := _u.mutation.SupportedModelScopes(); ok {
		_spec.SetField(group.FieldSupportedModelScopes, field.TypeJSON, value)
	}
	if value, ok := _u.mutation.AppendedSupportedModelScopes(); ok {
		_spec.AddModifier(func(u *sql.UpdateBuilder) {
			sqljson.Append(u, group.FieldSupportedModelScopes, value)
		})
	}
	if value, ok := _u.mutation.SortOrder(); ok {
		_spec.SetField(group.FieldSortOrder, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedSortOrder(); ok {
		_spec.AddField(group.FieldSortOrder, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AllowMessagesDispatch(); ok {
		_spec.SetField(group.FieldAllowMessagesDispatch, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RequireOauthOnly(); ok {
		_spec.SetField(group.FieldRequireOauthOnly, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RequirePrivacySet(); ok {
		_spec.SetField(group.FieldRequirePrivacySet, field.TypeBool, value)
	}
	if value, ok := _u.mutation.DefaultMappedModel(); ok {
		_spec.SetField(group.FieldDefaultMappedModel, field.TypeString, value)
	}
	if value, ok := _u.mutation.MessagesDispatchModelConfig(); ok {
		_spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value)
	}
	if _u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.APIKeysTable,
			Columns: []string{group.APIKeysColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAPIKeysIDs(); len(nodes) > 0 && !_u.mutation.APIKeysCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.APIKeysTable,
			Columns: []string{group.APIKeysColumn},
			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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.APIKeysIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.APIKeysTable,
			Columns: []string{group.APIKeysColumn},
			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.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.RedeemCodesTable,
			Columns: []string{group.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedRedeemCodesIDs(); len(nodes) > 0 && !_u.mutation.RedeemCodesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.RedeemCodesTable,
			Columns: []string{group.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RedeemCodesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.RedeemCodesTable,
			Columns: []string{group.RedeemCodesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(redeemcode.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.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.SubscriptionsTable,
			Columns: []string{group.SubscriptionsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.SubscriptionsTable,
			Columns: []string{group.SubscriptionsColumn},
			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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.SubscriptionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.SubscriptionsTable,
			Columns: []string{group.SubscriptionsColumn},
			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 _u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.UsageLogsTable,
			Columns: []string{group.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.UsageLogsTable,
			Columns: []string{group.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   group.UsageLogsTable,
			Columns: []string{group.UsageLogsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usagelog.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.AccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AccountsTable,
			Columns: group.AccountsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AccountsTable,
			Columns: group.AccountsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AccountsTable,
			Columns: group.AccountsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _u.mutation.AllowedUsersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AllowedUsersTable,
			Columns: group.AllowedUsersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.RemovedAllowedUsersIDs(); len(nodes) > 0 && !_u.mutation.AllowedUsersCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AllowedUsersTable,
			Columns: group.AllowedUsersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.AllowedUsersIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   group.AllowedUsersTable,
			Columns: group.AllowedUsersPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
		createE.defaults()
		_, specE := createE.createSpec()
		edge.Target.Fields = specE.Fields
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Group{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{group.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
