// 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"
	"database/sql"

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

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

	"gorm.io/plugin/dbresolver"

	"kra/internal/data/model"
)

func newSysBaseMenu(db *gorm.DB, opts ...gen.DOOption) sysBaseMenu {
	_sysBaseMenu := sysBaseMenu{}

	_sysBaseMenu.sysBaseMenuDo.UseDB(db, opts...)
	_sysBaseMenu.sysBaseMenuDo.UseModel(&model.SysBaseMenu{})

	tableName := _sysBaseMenu.sysBaseMenuDo.TableName()
	_sysBaseMenu.ALL = field.NewAsterisk(tableName)
	_sysBaseMenu.ID = field.NewInt64(tableName, "id")
	_sysBaseMenu.CreatedAt = field.NewTime(tableName, "created_at")
	_sysBaseMenu.UpdatedAt = field.NewTime(tableName, "updated_at")
	_sysBaseMenu.DeletedAt = field.NewField(tableName, "deleted_at")
	_sysBaseMenu.MenuLevel = field.NewInt64(tableName, "menu_level")
	_sysBaseMenu.ParentID = field.NewInt64(tableName, "parent_id")
	_sysBaseMenu.Path = field.NewString(tableName, "path")
	_sysBaseMenu.Name = field.NewString(tableName, "name")
	_sysBaseMenu.Hidden = field.NewBool(tableName, "hidden")
	_sysBaseMenu.Component = field.NewString(tableName, "component")
	_sysBaseMenu.Sort = field.NewInt64(tableName, "sort")
	_sysBaseMenu.ActiveName = field.NewString(tableName, "active_name")
	_sysBaseMenu.KeepAlive = field.NewBool(tableName, "keep_alive")
	_sysBaseMenu.DefaultMenu = field.NewBool(tableName, "default_menu")
	_sysBaseMenu.Title = field.NewString(tableName, "title")
	_sysBaseMenu.Icon = field.NewString(tableName, "icon")
	_sysBaseMenu.CloseTab = field.NewBool(tableName, "close_tab")
	_sysBaseMenu.TransitionType = field.NewString(tableName, "transition_type")

	_sysBaseMenu.fillFieldMap()

	return _sysBaseMenu
}

type sysBaseMenu struct {
	sysBaseMenuDo sysBaseMenuDo

	ALL            field.Asterisk
	ID             field.Int64
	CreatedAt      field.Time
	UpdatedAt      field.Time
	DeletedAt      field.Field
	MenuLevel      field.Int64
	ParentID       field.Int64  // 父菜单ID
	Path           field.String // 路由path
	Name           field.String // 路由name
	Hidden         field.Bool   // 是否在列表隐藏
	Component      field.String // 对应前端文件路径
	Sort           field.Int64  // 排序标记
	ActiveName     field.String // 高亮菜单
	KeepAlive      field.Bool   // 是否缓存
	DefaultMenu    field.Bool   // 是否是基础路由（开发中）
	Title          field.String // 菜单名
	Icon           field.String // 菜单图标
	CloseTab       field.Bool   // 自动关闭tab
	TransitionType field.String // 路由切换动画

	fieldMap map[string]field.Expr
}

func (s sysBaseMenu) Table(newTableName string) *sysBaseMenu {
	s.sysBaseMenuDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s sysBaseMenu) As(alias string) *sysBaseMenu {
	s.sysBaseMenuDo.DO = *(s.sysBaseMenuDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *sysBaseMenu) updateTableName(table string) *sysBaseMenu {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt64(table, "id")
	s.CreatedAt = field.NewTime(table, "created_at")
	s.UpdatedAt = field.NewTime(table, "updated_at")
	s.DeletedAt = field.NewField(table, "deleted_at")
	s.MenuLevel = field.NewInt64(table, "menu_level")
	s.ParentID = field.NewInt64(table, "parent_id")
	s.Path = field.NewString(table, "path")
	s.Name = field.NewString(table, "name")
	s.Hidden = field.NewBool(table, "hidden")
	s.Component = field.NewString(table, "component")
	s.Sort = field.NewInt64(table, "sort")
	s.ActiveName = field.NewString(table, "active_name")
	s.KeepAlive = field.NewBool(table, "keep_alive")
	s.DefaultMenu = field.NewBool(table, "default_menu")
	s.Title = field.NewString(table, "title")
	s.Icon = field.NewString(table, "icon")
	s.CloseTab = field.NewBool(table, "close_tab")
	s.TransitionType = field.NewString(table, "transition_type")

	s.fillFieldMap()

	return s
}

func (s *sysBaseMenu) WithContext(ctx context.Context) ISysBaseMenuDo {
	return s.sysBaseMenuDo.WithContext(ctx)
}

func (s sysBaseMenu) TableName() string { return s.sysBaseMenuDo.TableName() }

func (s sysBaseMenu) Alias() string { return s.sysBaseMenuDo.Alias() }

func (s sysBaseMenu) Columns(cols ...field.Expr) gen.Columns { return s.sysBaseMenuDo.Columns(cols...) }

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

func (s *sysBaseMenu) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 18)
	s.fieldMap["id"] = s.ID
	s.fieldMap["created_at"] = s.CreatedAt
	s.fieldMap["updated_at"] = s.UpdatedAt
	s.fieldMap["deleted_at"] = s.DeletedAt
	s.fieldMap["menu_level"] = s.MenuLevel
	s.fieldMap["parent_id"] = s.ParentID
	s.fieldMap["path"] = s.Path
	s.fieldMap["name"] = s.Name
	s.fieldMap["hidden"] = s.Hidden
	s.fieldMap["component"] = s.Component
	s.fieldMap["sort"] = s.Sort
	s.fieldMap["active_name"] = s.ActiveName
	s.fieldMap["keep_alive"] = s.KeepAlive
	s.fieldMap["default_menu"] = s.DefaultMenu
	s.fieldMap["title"] = s.Title
	s.fieldMap["icon"] = s.Icon
	s.fieldMap["close_tab"] = s.CloseTab
	s.fieldMap["transition_type"] = s.TransitionType
}

func (s sysBaseMenu) clone(db *gorm.DB) sysBaseMenu {
	s.sysBaseMenuDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s sysBaseMenu) replaceDB(db *gorm.DB) sysBaseMenu {
	s.sysBaseMenuDo.ReplaceDB(db)
	return s
}

type sysBaseMenuDo struct{ gen.DO }

type ISysBaseMenuDo interface {
	gen.SubQuery
	Debug() ISysBaseMenuDo
	WithContext(ctx context.Context) ISysBaseMenuDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() ISysBaseMenuDo
	WriteDB() ISysBaseMenuDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) ISysBaseMenuDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) ISysBaseMenuDo
	Not(conds ...gen.Condition) ISysBaseMenuDo
	Or(conds ...gen.Condition) ISysBaseMenuDo
	Select(conds ...field.Expr) ISysBaseMenuDo
	Where(conds ...gen.Condition) ISysBaseMenuDo
	Order(conds ...field.Expr) ISysBaseMenuDo
	Distinct(cols ...field.Expr) ISysBaseMenuDo
	Omit(cols ...field.Expr) ISysBaseMenuDo
	Join(table schema.Tabler, on ...field.Expr) ISysBaseMenuDo
	LeftJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuDo
	RightJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuDo
	Group(cols ...field.Expr) ISysBaseMenuDo
	Having(conds ...gen.Condition) ISysBaseMenuDo
	Limit(limit int) ISysBaseMenuDo
	Offset(offset int) ISysBaseMenuDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) ISysBaseMenuDo
	Unscoped() ISysBaseMenuDo
	Create(values ...*model.SysBaseMenu) error
	CreateInBatches(values []*model.SysBaseMenu, batchSize int) error
	Save(values ...*model.SysBaseMenu) error
	First() (*model.SysBaseMenu, error)
	Take() (*model.SysBaseMenu, error)
	Last() (*model.SysBaseMenu, error)
	Find() ([]*model.SysBaseMenu, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SysBaseMenu, err error)
	FindInBatches(result *[]*model.SysBaseMenu, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.SysBaseMenu) (info gen.ResultInfo, err error)
	Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	Updates(value interface{}) (info gen.ResultInfo, err error)
	UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
	UpdateFrom(q gen.SubQuery) gen.Dao
	Attrs(attrs ...field.AssignExpr) ISysBaseMenuDo
	Assign(attrs ...field.AssignExpr) ISysBaseMenuDo
	Joins(fields ...field.RelationField) ISysBaseMenuDo
	Preload(fields ...field.RelationField) ISysBaseMenuDo
	FirstOrInit() (*model.SysBaseMenu, error)
	FirstOrCreate() (*model.SysBaseMenu, error)
	FindByPage(offset int, limit int) (result []*model.SysBaseMenu, count int64, err error)
	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
	Rows() (*sql.Rows, error)
	Row() *sql.Row
	Scan(result interface{}) (err error)
	Returning(value interface{}, columns ...string) ISysBaseMenuDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (s sysBaseMenuDo) Debug() ISysBaseMenuDo {
	return s.withDO(s.DO.Debug())
}

func (s sysBaseMenuDo) WithContext(ctx context.Context) ISysBaseMenuDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysBaseMenuDo) ReadDB() ISysBaseMenuDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysBaseMenuDo) WriteDB() ISysBaseMenuDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysBaseMenuDo) Session(config *gorm.Session) ISysBaseMenuDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysBaseMenuDo) Clauses(conds ...clause.Expression) ISysBaseMenuDo {
	return s.withDO(s.DO.Clauses(conds...))
}

func (s sysBaseMenuDo) Returning(value interface{}, columns ...string) ISysBaseMenuDo {
	return s.withDO(s.DO.Returning(value, columns...))
}

func (s sysBaseMenuDo) Not(conds ...gen.Condition) ISysBaseMenuDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysBaseMenuDo) Or(conds ...gen.Condition) ISysBaseMenuDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysBaseMenuDo) Select(conds ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysBaseMenuDo) Where(conds ...gen.Condition) ISysBaseMenuDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysBaseMenuDo) Order(conds ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysBaseMenuDo) Distinct(cols ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysBaseMenuDo) Omit(cols ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.Omit(cols...))
}

func (s sysBaseMenuDo) Join(table schema.Tabler, on ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.Join(table, on...))
}

func (s sysBaseMenuDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.LeftJoin(table, on...))
}

func (s sysBaseMenuDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.RightJoin(table, on...))
}

func (s sysBaseMenuDo) Group(cols ...field.Expr) ISysBaseMenuDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysBaseMenuDo) Having(conds ...gen.Condition) ISysBaseMenuDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysBaseMenuDo) Limit(limit int) ISysBaseMenuDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysBaseMenuDo) Offset(offset int) ISysBaseMenuDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysBaseMenuDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysBaseMenuDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysBaseMenuDo) Unscoped() ISysBaseMenuDo {
	return s.withDO(s.DO.Unscoped())
}

func (s sysBaseMenuDo) Create(values ...*model.SysBaseMenu) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

func (s sysBaseMenuDo) CreateInBatches(values []*model.SysBaseMenu, batchSize int) error {
	return s.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 (s sysBaseMenuDo) Save(values ...*model.SysBaseMenu) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Save(values)
}

func (s sysBaseMenuDo) First() (*model.SysBaseMenu, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBaseMenu), nil
	}
}

func (s sysBaseMenuDo) Take() (*model.SysBaseMenu, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBaseMenu), nil
	}
}

func (s sysBaseMenuDo) Last() (*model.SysBaseMenu, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBaseMenu), nil
	}
}

func (s sysBaseMenuDo) Find() ([]*model.SysBaseMenu, error) {
	result, err := s.DO.Find()
	return result.([]*model.SysBaseMenu), err
}

func (s sysBaseMenuDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SysBaseMenu, err error) {
	buf := make([]*model.SysBaseMenu, 0, batchSize)
	err = s.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 (s sysBaseMenuDo) FindInBatches(result *[]*model.SysBaseMenu, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return s.DO.FindInBatches(result, batchSize, fc)
}

func (s sysBaseMenuDo) Attrs(attrs ...field.AssignExpr) ISysBaseMenuDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysBaseMenuDo) Assign(attrs ...field.AssignExpr) ISysBaseMenuDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s sysBaseMenuDo) FirstOrInit() (*model.SysBaseMenu, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBaseMenu), nil
	}
}

func (s sysBaseMenuDo) FirstOrCreate() (*model.SysBaseMenu, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysBaseMenu), nil
	}
}

func (s sysBaseMenuDo) FindByPage(offset int, limit int) (result []*model.SysBaseMenu, count int64, err error) {
	result, err = s.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 = s.Offset(-1).Limit(-1).Count()
	return
}

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

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

func (s sysBaseMenuDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s sysBaseMenuDo) Delete(models ...*model.SysBaseMenu) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *sysBaseMenuDo) withDO(do gen.Dao) *sysBaseMenuDo {
	s.DO = *do.(*gen.DO)
	return s
}
