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

	_sysAuthorityBtn.sysAuthorityBtnDo.UseDB(db, opts...)
	_sysAuthorityBtn.sysAuthorityBtnDo.UseModel(&model.SysAuthorityBtn{})

	tableName := _sysAuthorityBtn.sysAuthorityBtnDo.TableName()
	_sysAuthorityBtn.ALL = field.NewAsterisk(tableName)
	_sysAuthorityBtn.AuthorityID = field.NewInt64(tableName, "authority_id")
	_sysAuthorityBtn.SysMenuID = field.NewInt64(tableName, "sys_menu_id")
	_sysAuthorityBtn.SysBaseMenuBtnID = field.NewInt64(tableName, "sys_base_menu_btn_id")

	_sysAuthorityBtn.fillFieldMap()

	return _sysAuthorityBtn
}

type sysAuthorityBtn struct {
	sysAuthorityBtnDo sysAuthorityBtnDo

	ALL              field.Asterisk
	AuthorityID      field.Int64 // 角色ID
	SysMenuID        field.Int64 // 菜单ID
	SysBaseMenuBtnID field.Int64 // 菜单按钮ID

	fieldMap map[string]field.Expr
}

func (s sysAuthorityBtn) Table(newTableName string) *sysAuthorityBtn {
	s.sysAuthorityBtnDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

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

func (s *sysAuthorityBtn) updateTableName(table string) *sysAuthorityBtn {
	s.ALL = field.NewAsterisk(table)
	s.AuthorityID = field.NewInt64(table, "authority_id")
	s.SysMenuID = field.NewInt64(table, "sys_menu_id")
	s.SysBaseMenuBtnID = field.NewInt64(table, "sys_base_menu_btn_id")

	s.fillFieldMap()

	return s
}

func (s *sysAuthorityBtn) WithContext(ctx context.Context) ISysAuthorityBtnDo {
	return s.sysAuthorityBtnDo.WithContext(ctx)
}

func (s sysAuthorityBtn) TableName() string { return s.sysAuthorityBtnDo.TableName() }

func (s sysAuthorityBtn) Alias() string { return s.sysAuthorityBtnDo.Alias() }

func (s sysAuthorityBtn) Columns(cols ...field.Expr) gen.Columns {
	return s.sysAuthorityBtnDo.Columns(cols...)
}

func (s *sysAuthorityBtn) 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 *sysAuthorityBtn) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 3)
	s.fieldMap["authority_id"] = s.AuthorityID
	s.fieldMap["sys_menu_id"] = s.SysMenuID
	s.fieldMap["sys_base_menu_btn_id"] = s.SysBaseMenuBtnID
}

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

func (s sysAuthorityBtn) replaceDB(db *gorm.DB) sysAuthorityBtn {
	s.sysAuthorityBtnDo.ReplaceDB(db)
	return s
}

type sysAuthorityBtnDo struct{ gen.DO }

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

func (s sysAuthorityBtnDo) Debug() ISysAuthorityBtnDo {
	return s.withDO(s.DO.Debug())
}

func (s sysAuthorityBtnDo) WithContext(ctx context.Context) ISysAuthorityBtnDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysAuthorityBtnDo) ReadDB() ISysAuthorityBtnDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysAuthorityBtnDo) WriteDB() ISysAuthorityBtnDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysAuthorityBtnDo) Session(config *gorm.Session) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysAuthorityBtnDo) Clauses(conds ...clause.Expression) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sysAuthorityBtnDo) Not(conds ...gen.Condition) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysAuthorityBtnDo) Or(conds ...gen.Condition) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysAuthorityBtnDo) Select(conds ...field.Expr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysAuthorityBtnDo) Where(conds ...gen.Condition) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysAuthorityBtnDo) Order(conds ...field.Expr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysAuthorityBtnDo) Distinct(cols ...field.Expr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysAuthorityBtnDo) Omit(cols ...field.Expr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sysAuthorityBtnDo) Group(cols ...field.Expr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysAuthorityBtnDo) Having(conds ...gen.Condition) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysAuthorityBtnDo) Limit(limit int) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysAuthorityBtnDo) Offset(offset int) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysAuthorityBtnDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysAuthorityBtnDo) Unscoped() ISysAuthorityBtnDo {
	return s.withDO(s.DO.Unscoped())
}

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

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

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

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

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

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

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

func (s sysAuthorityBtnDo) Attrs(attrs ...field.AssignExpr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysAuthorityBtnDo) Assign(attrs ...field.AssignExpr) ISysAuthorityBtnDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

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

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

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

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

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