// 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 query

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newAdminMenu(db *gorm.DB, opts ...gen.DOOption) adminMenu {
	_adminMenu := adminMenu{}

	_adminMenu.adminMenuDo.UseDB(db, opts...)
	_adminMenu.adminMenuDo.UseModel(&model.AdminMenu{})

	tableName := _adminMenu.adminMenuDo.TableName()
	_adminMenu.ALL = field.NewAsterisk(tableName)
	_adminMenu.ID = field.NewInt32(tableName, "id")
	_adminMenu.SystemID = field.NewInt32(tableName, "system_id")
	_adminMenu.Path = field.NewString(tableName, "path")
	_adminMenu.Name = field.NewString(tableName, "name")
	_adminMenu.Component = field.NewString(tableName, "component")
	_adminMenu.Redirect = field.NewString(tableName, "redirect")
	_adminMenu.Icon = field.NewString(tableName, "icon")
	_adminMenu.Title = field.NewString(tableName, "title")
	_adminMenu.Sort = field.NewInt32(tableName, "sort")
	_adminMenu.IsRoot = field.NewInt32(tableName, "is_root")
	_adminMenu.ActiveMenu = field.NewString(tableName, "active_menu")
	_adminMenu.Hidden = field.NewInt32(tableName, "hidden")
	_adminMenu.ParentID = field.NewInt32(tableName, "parent_id")
	_adminMenu.Disable = field.NewInt32(tableName, "disable")
	_adminMenu.IsSuper = field.NewInt32(tableName, "is_super")
	_adminMenu.LocalShow = field.NewInt32(tableName, "local_show")
	_adminMenu.CreateAt = field.NewInt32(tableName, "create_at")
	_adminMenu.UpdateAt = field.NewInt32(tableName, "update_at")

	_adminMenu.fillFieldMap()

	return _adminMenu
}

type adminMenu struct {
	adminMenuDo

	ALL        field.Asterisk
	ID         field.Int32
	SystemID   field.Int32
	Path       field.String
	Name       field.String
	Component  field.String
	Redirect   field.String
	Icon       field.String
	Title      field.String
	Sort       field.Int32
	IsRoot     field.Int32 // 1 true
	ActiveMenu field.String
	Hidden     field.Int32 // 1隐藏
	ParentID   field.Int32
	Disable    field.Int32
	IsSuper    field.Int32 // 1只有管理员有查看权限
	LocalShow  field.Int32 // 1只在本地展示
	CreateAt   field.Int32
	UpdateAt   field.Int32

	fieldMap map[string]field.Expr
}

func (a adminMenu) Table(newTableName string) *adminMenu {
	a.adminMenuDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a adminMenu) As(alias string) *adminMenu {
	a.adminMenuDo.DO = *(a.adminMenuDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *adminMenu) updateTableName(table string) *adminMenu {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt32(table, "id")
	a.SystemID = field.NewInt32(table, "system_id")
	a.Path = field.NewString(table, "path")
	a.Name = field.NewString(table, "name")
	a.Component = field.NewString(table, "component")
	a.Redirect = field.NewString(table, "redirect")
	a.Icon = field.NewString(table, "icon")
	a.Title = field.NewString(table, "title")
	a.Sort = field.NewInt32(table, "sort")
	a.IsRoot = field.NewInt32(table, "is_root")
	a.ActiveMenu = field.NewString(table, "active_menu")
	a.Hidden = field.NewInt32(table, "hidden")
	a.ParentID = field.NewInt32(table, "parent_id")
	a.Disable = field.NewInt32(table, "disable")
	a.IsSuper = field.NewInt32(table, "is_super")
	a.LocalShow = field.NewInt32(table, "local_show")
	a.CreateAt = field.NewInt32(table, "create_at")
	a.UpdateAt = field.NewInt32(table, "update_at")

	a.fillFieldMap()

	return a
}

func (a *adminMenu) WithContext(ctx context.Context) *adminMenuDo {
	return a.adminMenuDo.WithContext(ctx)
}

func (a adminMenu) TableName() string { return a.adminMenuDo.TableName() }

func (a adminMenu) Alias() string { return a.adminMenuDo.Alias() }

func (a adminMenu) Columns(cols ...field.Expr) gen.Columns { return a.adminMenuDo.Columns(cols...) }

func (a *adminMenu) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := a.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (a *adminMenu) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 18)
	a.fieldMap["id"] = a.ID
	a.fieldMap["system_id"] = a.SystemID
	a.fieldMap["path"] = a.Path
	a.fieldMap["name"] = a.Name
	a.fieldMap["component"] = a.Component
	a.fieldMap["redirect"] = a.Redirect
	a.fieldMap["icon"] = a.Icon
	a.fieldMap["title"] = a.Title
	a.fieldMap["sort"] = a.Sort
	a.fieldMap["is_root"] = a.IsRoot
	a.fieldMap["active_menu"] = a.ActiveMenu
	a.fieldMap["hidden"] = a.Hidden
	a.fieldMap["parent_id"] = a.ParentID
	a.fieldMap["disable"] = a.Disable
	a.fieldMap["is_super"] = a.IsSuper
	a.fieldMap["local_show"] = a.LocalShow
	a.fieldMap["create_at"] = a.CreateAt
	a.fieldMap["update_at"] = a.UpdateAt
}

func (a adminMenu) clone(db *gorm.DB) adminMenu {
	a.adminMenuDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a adminMenu) replaceDB(db *gorm.DB) adminMenu {
	a.adminMenuDo.ReplaceDB(db)
	return a
}

type adminMenuDo struct{ gen.DO }

func (a adminMenuDo) Debug() *adminMenuDo {
	return a.withDO(a.DO.Debug())
}

func (a adminMenuDo) WithContext(ctx context.Context) *adminMenuDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a adminMenuDo) ReadDB() *adminMenuDo {
	return a.Clauses(dbresolver.Read)
}

func (a adminMenuDo) WriteDB() *adminMenuDo {
	return a.Clauses(dbresolver.Write)
}

func (a adminMenuDo) Session(config *gorm.Session) *adminMenuDo {
	return a.withDO(a.DO.Session(config))
}

func (a adminMenuDo) Clauses(conds ...clause.Expression) *adminMenuDo {
	return a.withDO(a.DO.Clauses(conds...))
}

func (a adminMenuDo) Returning(value interface{}, columns ...string) *adminMenuDo {
	return a.withDO(a.DO.Returning(value, columns...))
}

func (a adminMenuDo) Not(conds ...gen.Condition) *adminMenuDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a adminMenuDo) Or(conds ...gen.Condition) *adminMenuDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a adminMenuDo) Select(conds ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a adminMenuDo) Where(conds ...gen.Condition) *adminMenuDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a adminMenuDo) Order(conds ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a adminMenuDo) Distinct(cols ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a adminMenuDo) Omit(cols ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.Omit(cols...))
}

func (a adminMenuDo) Join(table schema.Tabler, on ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.Join(table, on...))
}

func (a adminMenuDo) LeftJoin(table schema.Tabler, on ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.LeftJoin(table, on...))
}

func (a adminMenuDo) RightJoin(table schema.Tabler, on ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.RightJoin(table, on...))
}

func (a adminMenuDo) Group(cols ...field.Expr) *adminMenuDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a adminMenuDo) Having(conds ...gen.Condition) *adminMenuDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a adminMenuDo) Limit(limit int) *adminMenuDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a adminMenuDo) Offset(offset int) *adminMenuDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a adminMenuDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *adminMenuDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a adminMenuDo) Unscoped() *adminMenuDo {
	return a.withDO(a.DO.Unscoped())
}

func (a adminMenuDo) Create(values ...*model.AdminMenu) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

func (a adminMenuDo) CreateInBatches(values []*model.AdminMenu, batchSize int) error {
	return a.DO.CreateInBatches(values, batchSize)
}

// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a adminMenuDo) Save(values ...*model.AdminMenu) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Save(values)
}

func (a adminMenuDo) First() (*model.AdminMenu, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminMenu), nil
	}
}

func (a adminMenuDo) Take() (*model.AdminMenu, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminMenu), nil
	}
}

func (a adminMenuDo) Last() (*model.AdminMenu, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminMenu), nil
	}
}

func (a adminMenuDo) Find() ([]*model.AdminMenu, error) {
	result, err := a.DO.Find()
	return result.([]*model.AdminMenu), err
}

func (a adminMenuDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AdminMenu, err error) {
	buf := make([]*model.AdminMenu, 0, batchSize)
	err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
		defer func() { results = append(results, buf...) }()
		return fc(tx, batch)
	})
	return results, err
}

func (a adminMenuDo) FindInBatches(result *[]*model.AdminMenu, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return a.DO.FindInBatches(result, batchSize, fc)
}

func (a adminMenuDo) Attrs(attrs ...field.AssignExpr) *adminMenuDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a adminMenuDo) Assign(attrs ...field.AssignExpr) *adminMenuDo {
	return a.withDO(a.DO.Assign(attrs...))
}

func (a adminMenuDo) Joins(fields ...field.RelationField) *adminMenuDo {
	for _, _f := range fields {
		a = *a.withDO(a.DO.Joins(_f))
	}
	return &a
}

func (a adminMenuDo) Preload(fields ...field.RelationField) *adminMenuDo {
	for _, _f := range fields {
		a = *a.withDO(a.DO.Preload(_f))
	}
	return &a
}

func (a adminMenuDo) FirstOrInit() (*model.AdminMenu, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminMenu), nil
	}
}

func (a adminMenuDo) FirstOrCreate() (*model.AdminMenu, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminMenu), nil
	}
}

func (a adminMenuDo) FindByPage(offset int, limit int) (result []*model.AdminMenu, count int64, err error) {
	result, err = a.Offset(offset).Limit(limit).Find()
	if err != nil {
		return
	}

	if size := len(result); 0 < limit && 0 < size && size < limit {
		count = int64(size + offset)
		return
	}

	count, err = a.Offset(-1).Limit(-1).Count()
	return
}

func (a adminMenuDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = a.Count()
	if err != nil {
		return
	}

	err = a.Offset(offset).Limit(limit).Scan(result)
	return
}

func (a adminMenuDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a adminMenuDo) Delete(models ...*model.AdminMenu) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *adminMenuDo) withDO(do gen.Dao) *adminMenuDo {
	a.DO = *do.(*gen.DO)
	return a
}
