// 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 newSysBaseMenuBtn(db *gorm.DB, opts ...gen.DOOption) sysBaseMenuBtn {
	_sysBaseMenuBtn := sysBaseMenuBtn{}

	_sysBaseMenuBtn.sysBaseMenuBtnDo.UseDB(db, opts...)
	_sysBaseMenuBtn.sysBaseMenuBtnDo.UseModel(&model.SysBaseMenuBtn{})

	tableName := _sysBaseMenuBtn.sysBaseMenuBtnDo.TableName()
	_sysBaseMenuBtn.ALL = field.NewAsterisk(tableName)
	_sysBaseMenuBtn.ID = field.NewInt64(tableName, "id")
	_sysBaseMenuBtn.CreatedAt = field.NewTime(tableName, "created_at")
	_sysBaseMenuBtn.UpdatedAt = field.NewTime(tableName, "updated_at")
	_sysBaseMenuBtn.DeletedAt = field.NewField(tableName, "deleted_at")
	_sysBaseMenuBtn.Name = field.NewString(tableName, "name")
	_sysBaseMenuBtn.Desc = field.NewString(tableName, "desc")
	_sysBaseMenuBtn.SysBaseMenuID = field.NewInt64(tableName, "sys_base_menu_id")

	_sysBaseMenuBtn.fillFieldMap()

	return _sysBaseMenuBtn
}

type sysBaseMenuBtn struct {
	sysBaseMenuBtnDo sysBaseMenuBtnDo

	ALL           field.Asterisk
	ID            field.Int64
	CreatedAt     field.Time
	UpdatedAt     field.Time
	DeletedAt     field.Field
	Name          field.String // 按钮关键key
	Desc          field.String
	SysBaseMenuID field.Int64 // 菜单ID

	fieldMap map[string]field.Expr
}

func (s sysBaseMenuBtn) Table(newTableName string) *sysBaseMenuBtn {
	s.sysBaseMenuBtnDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

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

func (s *sysBaseMenuBtn) updateTableName(table string) *sysBaseMenuBtn {
	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.Name = field.NewString(table, "name")
	s.Desc = field.NewString(table, "desc")
	s.SysBaseMenuID = field.NewInt64(table, "sys_base_menu_id")

	s.fillFieldMap()

	return s
}

func (s *sysBaseMenuBtn) WithContext(ctx context.Context) ISysBaseMenuBtnDo {
	return s.sysBaseMenuBtnDo.WithContext(ctx)
}

func (s sysBaseMenuBtn) TableName() string { return s.sysBaseMenuBtnDo.TableName() }

func (s sysBaseMenuBtn) Alias() string { return s.sysBaseMenuBtnDo.Alias() }

func (s sysBaseMenuBtn) Columns(cols ...field.Expr) gen.Columns {
	return s.sysBaseMenuBtnDo.Columns(cols...)
}

func (s *sysBaseMenuBtn) 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 *sysBaseMenuBtn) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 7)
	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["name"] = s.Name
	s.fieldMap["desc"] = s.Desc
	s.fieldMap["sys_base_menu_id"] = s.SysBaseMenuID
}

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

func (s sysBaseMenuBtn) replaceDB(db *gorm.DB) sysBaseMenuBtn {
	s.sysBaseMenuBtnDo.ReplaceDB(db)
	return s
}

type sysBaseMenuBtnDo struct{ gen.DO }

type ISysBaseMenuBtnDo interface {
	gen.SubQuery
	Debug() ISysBaseMenuBtnDo
	WithContext(ctx context.Context) ISysBaseMenuBtnDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() ISysBaseMenuBtnDo
	WriteDB() ISysBaseMenuBtnDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) ISysBaseMenuBtnDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) ISysBaseMenuBtnDo
	Not(conds ...gen.Condition) ISysBaseMenuBtnDo
	Or(conds ...gen.Condition) ISysBaseMenuBtnDo
	Select(conds ...field.Expr) ISysBaseMenuBtnDo
	Where(conds ...gen.Condition) ISysBaseMenuBtnDo
	Order(conds ...field.Expr) ISysBaseMenuBtnDo
	Distinct(cols ...field.Expr) ISysBaseMenuBtnDo
	Omit(cols ...field.Expr) ISysBaseMenuBtnDo
	Join(table schema.Tabler, on ...field.Expr) ISysBaseMenuBtnDo
	LeftJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuBtnDo
	RightJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuBtnDo
	Group(cols ...field.Expr) ISysBaseMenuBtnDo
	Having(conds ...gen.Condition) ISysBaseMenuBtnDo
	Limit(limit int) ISysBaseMenuBtnDo
	Offset(offset int) ISysBaseMenuBtnDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) ISysBaseMenuBtnDo
	Unscoped() ISysBaseMenuBtnDo
	Create(values ...*model.SysBaseMenuBtn) error
	CreateInBatches(values []*model.SysBaseMenuBtn, batchSize int) error
	Save(values ...*model.SysBaseMenuBtn) error
	First() (*model.SysBaseMenuBtn, error)
	Take() (*model.SysBaseMenuBtn, error)
	Last() (*model.SysBaseMenuBtn, error)
	Find() ([]*model.SysBaseMenuBtn, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SysBaseMenuBtn, err error)
	FindInBatches(result *[]*model.SysBaseMenuBtn, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.SysBaseMenuBtn) (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) ISysBaseMenuBtnDo
	Assign(attrs ...field.AssignExpr) ISysBaseMenuBtnDo
	Joins(fields ...field.RelationField) ISysBaseMenuBtnDo
	Preload(fields ...field.RelationField) ISysBaseMenuBtnDo
	FirstOrInit() (*model.SysBaseMenuBtn, error)
	FirstOrCreate() (*model.SysBaseMenuBtn, error)
	FindByPage(offset int, limit int) (result []*model.SysBaseMenuBtn, 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) ISysBaseMenuBtnDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (s sysBaseMenuBtnDo) Debug() ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Debug())
}

func (s sysBaseMenuBtnDo) WithContext(ctx context.Context) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysBaseMenuBtnDo) ReadDB() ISysBaseMenuBtnDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysBaseMenuBtnDo) WriteDB() ISysBaseMenuBtnDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysBaseMenuBtnDo) Session(config *gorm.Session) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysBaseMenuBtnDo) Clauses(conds ...clause.Expression) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sysBaseMenuBtnDo) Not(conds ...gen.Condition) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysBaseMenuBtnDo) Or(conds ...gen.Condition) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysBaseMenuBtnDo) Select(conds ...field.Expr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysBaseMenuBtnDo) Where(conds ...gen.Condition) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysBaseMenuBtnDo) Order(conds ...field.Expr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysBaseMenuBtnDo) Distinct(cols ...field.Expr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysBaseMenuBtnDo) Omit(cols ...field.Expr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sysBaseMenuBtnDo) Group(cols ...field.Expr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysBaseMenuBtnDo) Having(conds ...gen.Condition) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysBaseMenuBtnDo) Limit(limit int) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysBaseMenuBtnDo) Offset(offset int) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysBaseMenuBtnDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysBaseMenuBtnDo) Unscoped() ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Unscoped())
}

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

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

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

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

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

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

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

func (s sysBaseMenuBtnDo) Attrs(attrs ...field.AssignExpr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysBaseMenuBtnDo) Assign(attrs ...field.AssignExpr) ISysBaseMenuBtnDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

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

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

func (s sysBaseMenuBtnDo) FindByPage(offset int, limit int) (result []*model.SysBaseMenuBtn, 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 sysBaseMenuBtnDo) 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 sysBaseMenuBtnDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

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

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