// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.

package dao

import (
	"context"
	"database/sql"

	"gorm.io/gorm"

	"gorm.io/gen"

	"gorm.io/plugin/dbresolver"
)

var (
	Q                      = new(Query)
	Activities             *activities
	ActivityCategories     *activityCategories
	ActivityDrawEffects    *activityDrawEffects
	ActivityDrawLogs       *activityDrawLogs
	ActivityIssues         *activityIssues
	ActivityRewardSettings *activityRewardSettings
	Admin                  *admin
	Banner                 *banner
	Guild                  *guild
	GuildBoxes             *guildBoxes
	GuildContributeLogs    *guildContributeLogs
	GuildMembers           *guildMembers
	LogOperation           *logOperation
	LogRequest             *logRequest
	MenuActions            *menuActions
	Menus                  *menus
	OrderItems             *orderItems
	Orders                 *orders
	ProductCategories      *productCategories
	Products               *products
	RoleActions            *roleActions
	RoleMenus              *roleMenus
	RoleUsers              *roleUsers
	Roles                  *roles
	ShippingRecords        *shippingRecords
	SystemCoupons          *systemCoupons
	SystemItemCards        *systemItemCards
	UserAddresses          *userAddresses
	UserCoupons            *userCoupons
	UserInventory          *userInventory
	UserInventoryTransfers *userInventoryTransfers
	UserInvites            *userInvites
	UserItemCards          *userItemCards
	UserPoints             *userPoints
	UserPointsLedger       *userPointsLedger
	Users                  *users
)

func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
	*Q = *Use(db, opts...)
	Activities = &Q.Activities
	ActivityCategories = &Q.ActivityCategories
	ActivityDrawEffects = &Q.ActivityDrawEffects
	ActivityDrawLogs = &Q.ActivityDrawLogs
	ActivityIssues = &Q.ActivityIssues
	ActivityRewardSettings = &Q.ActivityRewardSettings
	Admin = &Q.Admin
	Banner = &Q.Banner
	Guild = &Q.Guild
	GuildBoxes = &Q.GuildBoxes
	GuildContributeLogs = &Q.GuildContributeLogs
	GuildMembers = &Q.GuildMembers
	LogOperation = &Q.LogOperation
	LogRequest = &Q.LogRequest
	MenuActions = &Q.MenuActions
	Menus = &Q.Menus
	OrderItems = &Q.OrderItems
	Orders = &Q.Orders
	ProductCategories = &Q.ProductCategories
	Products = &Q.Products
	RoleActions = &Q.RoleActions
	RoleMenus = &Q.RoleMenus
	RoleUsers = &Q.RoleUsers
	Roles = &Q.Roles
	ShippingRecords = &Q.ShippingRecords
	SystemCoupons = &Q.SystemCoupons
	SystemItemCards = &Q.SystemItemCards
	UserAddresses = &Q.UserAddresses
	UserCoupons = &Q.UserCoupons
	UserInventory = &Q.UserInventory
	UserInventoryTransfers = &Q.UserInventoryTransfers
	UserInvites = &Q.UserInvites
	UserItemCards = &Q.UserItemCards
	UserPoints = &Q.UserPoints
	UserPointsLedger = &Q.UserPointsLedger
	Users = &Q.Users
}

func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
	return &Query{
		db:                     db,
		Activities:             newActivities(db, opts...),
		ActivityCategories:     newActivityCategories(db, opts...),
		ActivityDrawEffects:    newActivityDrawEffects(db, opts...),
		ActivityDrawLogs:       newActivityDrawLogs(db, opts...),
		ActivityIssues:         newActivityIssues(db, opts...),
		ActivityRewardSettings: newActivityRewardSettings(db, opts...),
		Admin:                  newAdmin(db, opts...),
		Banner:                 newBanner(db, opts...),
		Guild:                  newGuild(db, opts...),
		GuildBoxes:             newGuildBoxes(db, opts...),
		GuildContributeLogs:    newGuildContributeLogs(db, opts...),
		GuildMembers:           newGuildMembers(db, opts...),
		LogOperation:           newLogOperation(db, opts...),
		LogRequest:             newLogRequest(db, opts...),
		MenuActions:            newMenuActions(db, opts...),
		Menus:                  newMenus(db, opts...),
		OrderItems:             newOrderItems(db, opts...),
		Orders:                 newOrders(db, opts...),
		ProductCategories:      newProductCategories(db, opts...),
		Products:               newProducts(db, opts...),
		RoleActions:            newRoleActions(db, opts...),
		RoleMenus:              newRoleMenus(db, opts...),
		RoleUsers:              newRoleUsers(db, opts...),
		Roles:                  newRoles(db, opts...),
		ShippingRecords:        newShippingRecords(db, opts...),
		SystemCoupons:          newSystemCoupons(db, opts...),
		SystemItemCards:        newSystemItemCards(db, opts...),
		UserAddresses:          newUserAddresses(db, opts...),
		UserCoupons:            newUserCoupons(db, opts...),
		UserInventory:          newUserInventory(db, opts...),
		UserInventoryTransfers: newUserInventoryTransfers(db, opts...),
		UserInvites:            newUserInvites(db, opts...),
		UserItemCards:          newUserItemCards(db, opts...),
		UserPoints:             newUserPoints(db, opts...),
		UserPointsLedger:       newUserPointsLedger(db, opts...),
		Users:                  newUsers(db, opts...),
	}
}

type Query struct {
	db *gorm.DB

	Activities             activities
	ActivityCategories     activityCategories
	ActivityDrawEffects    activityDrawEffects
	ActivityDrawLogs       activityDrawLogs
	ActivityIssues         activityIssues
	ActivityRewardSettings activityRewardSettings
	Admin                  admin
	Banner                 banner
	Guild                  guild
	GuildBoxes             guildBoxes
	GuildContributeLogs    guildContributeLogs
	GuildMembers           guildMembers
	LogOperation           logOperation
	LogRequest             logRequest
	MenuActions            menuActions
	Menus                  menus
	OrderItems             orderItems
	Orders                 orders
	ProductCategories      productCategories
	Products               products
	RoleActions            roleActions
	RoleMenus              roleMenus
	RoleUsers              roleUsers
	Roles                  roles
	ShippingRecords        shippingRecords
	SystemCoupons          systemCoupons
	SystemItemCards        systemItemCards
	UserAddresses          userAddresses
	UserCoupons            userCoupons
	UserInventory          userInventory
	UserInventoryTransfers userInventoryTransfers
	UserInvites            userInvites
	UserItemCards          userItemCards
	UserPoints             userPoints
	UserPointsLedger       userPointsLedger
	Users                  users
}

func (q *Query) Available() bool { return q.db != nil }

func (q *Query) clone(db *gorm.DB) *Query {
	return &Query{
		db:                     db,
		Activities:             q.Activities.clone(db),
		ActivityCategories:     q.ActivityCategories.clone(db),
		ActivityDrawEffects:    q.ActivityDrawEffects.clone(db),
		ActivityDrawLogs:       q.ActivityDrawLogs.clone(db),
		ActivityIssues:         q.ActivityIssues.clone(db),
		ActivityRewardSettings: q.ActivityRewardSettings.clone(db),
		Admin:                  q.Admin.clone(db),
		Banner:                 q.Banner.clone(db),
		Guild:                  q.Guild.clone(db),
		GuildBoxes:             q.GuildBoxes.clone(db),
		GuildContributeLogs:    q.GuildContributeLogs.clone(db),
		GuildMembers:           q.GuildMembers.clone(db),
		LogOperation:           q.LogOperation.clone(db),
		LogRequest:             q.LogRequest.clone(db),
		MenuActions:            q.MenuActions.clone(db),
		Menus:                  q.Menus.clone(db),
		OrderItems:             q.OrderItems.clone(db),
		Orders:                 q.Orders.clone(db),
		ProductCategories:      q.ProductCategories.clone(db),
		Products:               q.Products.clone(db),
		RoleActions:            q.RoleActions.clone(db),
		RoleMenus:              q.RoleMenus.clone(db),
		RoleUsers:              q.RoleUsers.clone(db),
		Roles:                  q.Roles.clone(db),
		ShippingRecords:        q.ShippingRecords.clone(db),
		SystemCoupons:          q.SystemCoupons.clone(db),
		SystemItemCards:        q.SystemItemCards.clone(db),
		UserAddresses:          q.UserAddresses.clone(db),
		UserCoupons:            q.UserCoupons.clone(db),
		UserInventory:          q.UserInventory.clone(db),
		UserInventoryTransfers: q.UserInventoryTransfers.clone(db),
		UserInvites:            q.UserInvites.clone(db),
		UserItemCards:          q.UserItemCards.clone(db),
		UserPoints:             q.UserPoints.clone(db),
		UserPointsLedger:       q.UserPointsLedger.clone(db),
		Users:                  q.Users.clone(db),
	}
}

func (q *Query) ReadDB() *Query {
	return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}

func (q *Query) WriteDB() *Query {
	return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}

func (q *Query) ReplaceDB(db *gorm.DB) *Query {
	return &Query{
		db:                     db,
		Activities:             q.Activities.replaceDB(db),
		ActivityCategories:     q.ActivityCategories.replaceDB(db),
		ActivityDrawEffects:    q.ActivityDrawEffects.replaceDB(db),
		ActivityDrawLogs:       q.ActivityDrawLogs.replaceDB(db),
		ActivityIssues:         q.ActivityIssues.replaceDB(db),
		ActivityRewardSettings: q.ActivityRewardSettings.replaceDB(db),
		Admin:                  q.Admin.replaceDB(db),
		Banner:                 q.Banner.replaceDB(db),
		Guild:                  q.Guild.replaceDB(db),
		GuildBoxes:             q.GuildBoxes.replaceDB(db),
		GuildContributeLogs:    q.GuildContributeLogs.replaceDB(db),
		GuildMembers:           q.GuildMembers.replaceDB(db),
		LogOperation:           q.LogOperation.replaceDB(db),
		LogRequest:             q.LogRequest.replaceDB(db),
		MenuActions:            q.MenuActions.replaceDB(db),
		Menus:                  q.Menus.replaceDB(db),
		OrderItems:             q.OrderItems.replaceDB(db),
		Orders:                 q.Orders.replaceDB(db),
		ProductCategories:      q.ProductCategories.replaceDB(db),
		Products:               q.Products.replaceDB(db),
		RoleActions:            q.RoleActions.replaceDB(db),
		RoleMenus:              q.RoleMenus.replaceDB(db),
		RoleUsers:              q.RoleUsers.replaceDB(db),
		Roles:                  q.Roles.replaceDB(db),
		ShippingRecords:        q.ShippingRecords.replaceDB(db),
		SystemCoupons:          q.SystemCoupons.replaceDB(db),
		SystemItemCards:        q.SystemItemCards.replaceDB(db),
		UserAddresses:          q.UserAddresses.replaceDB(db),
		UserCoupons:            q.UserCoupons.replaceDB(db),
		UserInventory:          q.UserInventory.replaceDB(db),
		UserInventoryTransfers: q.UserInventoryTransfers.replaceDB(db),
		UserInvites:            q.UserInvites.replaceDB(db),
		UserItemCards:          q.UserItemCards.replaceDB(db),
		UserPoints:             q.UserPoints.replaceDB(db),
		UserPointsLedger:       q.UserPointsLedger.replaceDB(db),
		Users:                  q.Users.replaceDB(db),
	}
}

type queryCtx struct {
	Activities             *activitiesDo
	ActivityCategories     *activityCategoriesDo
	ActivityDrawEffects    *activityDrawEffectsDo
	ActivityDrawLogs       *activityDrawLogsDo
	ActivityIssues         *activityIssuesDo
	ActivityRewardSettings *activityRewardSettingsDo
	Admin                  *adminDo
	Banner                 *bannerDo
	Guild                  *guildDo
	GuildBoxes             *guildBoxesDo
	GuildContributeLogs    *guildContributeLogsDo
	GuildMembers           *guildMembersDo
	LogOperation           *logOperationDo
	LogRequest             *logRequestDo
	MenuActions            *menuActionsDo
	Menus                  *menusDo
	OrderItems             *orderItemsDo
	Orders                 *ordersDo
	ProductCategories      *productCategoriesDo
	Products               *productsDo
	RoleActions            *roleActionsDo
	RoleMenus              *roleMenusDo
	RoleUsers              *roleUsersDo
	Roles                  *rolesDo
	ShippingRecords        *shippingRecordsDo
	SystemCoupons          *systemCouponsDo
	SystemItemCards        *systemItemCardsDo
	UserAddresses          *userAddressesDo
	UserCoupons            *userCouponsDo
	UserInventory          *userInventoryDo
	UserInventoryTransfers *userInventoryTransfersDo
	UserInvites            *userInvitesDo
	UserItemCards          *userItemCardsDo
	UserPoints             *userPointsDo
	UserPointsLedger       *userPointsLedgerDo
	Users                  *usersDo
}

func (q *Query) WithContext(ctx context.Context) *queryCtx {
	return &queryCtx{
		Activities:             q.Activities.WithContext(ctx),
		ActivityCategories:     q.ActivityCategories.WithContext(ctx),
		ActivityDrawEffects:    q.ActivityDrawEffects.WithContext(ctx),
		ActivityDrawLogs:       q.ActivityDrawLogs.WithContext(ctx),
		ActivityIssues:         q.ActivityIssues.WithContext(ctx),
		ActivityRewardSettings: q.ActivityRewardSettings.WithContext(ctx),
		Admin:                  q.Admin.WithContext(ctx),
		Banner:                 q.Banner.WithContext(ctx),
		Guild:                  q.Guild.WithContext(ctx),
		GuildBoxes:             q.GuildBoxes.WithContext(ctx),
		GuildContributeLogs:    q.GuildContributeLogs.WithContext(ctx),
		GuildMembers:           q.GuildMembers.WithContext(ctx),
		LogOperation:           q.LogOperation.WithContext(ctx),
		LogRequest:             q.LogRequest.WithContext(ctx),
		MenuActions:            q.MenuActions.WithContext(ctx),
		Menus:                  q.Menus.WithContext(ctx),
		OrderItems:             q.OrderItems.WithContext(ctx),
		Orders:                 q.Orders.WithContext(ctx),
		ProductCategories:      q.ProductCategories.WithContext(ctx),
		Products:               q.Products.WithContext(ctx),
		RoleActions:            q.RoleActions.WithContext(ctx),
		RoleMenus:              q.RoleMenus.WithContext(ctx),
		RoleUsers:              q.RoleUsers.WithContext(ctx),
		Roles:                  q.Roles.WithContext(ctx),
		ShippingRecords:        q.ShippingRecords.WithContext(ctx),
		SystemCoupons:          q.SystemCoupons.WithContext(ctx),
		SystemItemCards:        q.SystemItemCards.WithContext(ctx),
		UserAddresses:          q.UserAddresses.WithContext(ctx),
		UserCoupons:            q.UserCoupons.WithContext(ctx),
		UserInventory:          q.UserInventory.WithContext(ctx),
		UserInventoryTransfers: q.UserInventoryTransfers.WithContext(ctx),
		UserInvites:            q.UserInvites.WithContext(ctx),
		UserItemCards:          q.UserItemCards.WithContext(ctx),
		UserPoints:             q.UserPoints.WithContext(ctx),
		UserPointsLedger:       q.UserPointsLedger.WithContext(ctx),
		Users:                  q.Users.WithContext(ctx),
	}
}

func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
	return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}

func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
	tx := q.db.Begin(opts...)
	return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}

type QueryTx struct {
	*Query
	Error error
}

func (q *QueryTx) Commit() error {
	return q.db.Commit().Error
}

func (q *QueryTx) Rollback() error {
	return q.db.Rollback().Error
}

func (q *QueryTx) SavePoint(name string) error {
	return q.db.SavePoint(name).Error
}

func (q *QueryTx) RollbackTo(name string) error {
	return q.db.RollbackTo(name).Error
}
