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

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

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

	"gorm.io/plugin/dbresolver"

	"bindbox-game/internal/repository/mysql/model"
)

func newRoleMenus(db *gorm.DB, opts ...gen.DOOption) roleMenus {
	_roleMenus := roleMenus{}

	_roleMenus.roleMenusDo.UseDB(db, opts...)
	_roleMenus.roleMenusDo.UseModel(&model.RoleMenus{})

	tableName := _roleMenus.roleMenusDo.TableName()
	_roleMenus.ALL = field.NewAsterisk(tableName)
	_roleMenus.ID = field.NewInt64(tableName, "id")
	_roleMenus.RoleID = field.NewInt64(tableName, "role_id")
	_roleMenus.MenuID = field.NewInt64(tableName, "menu_id")
	_roleMenus.CreatedUser = field.NewString(tableName, "created_user")
	_roleMenus.UpdatedUser = field.NewString(tableName, "updated_user")
	_roleMenus.CreatedAt = field.NewTime(tableName, "created_at")
	_roleMenus.UpdatedAt = field.NewTime(tableName, "updated_at")

	_roleMenus.fillFieldMap()

	return _roleMenus
}

type roleMenus struct {
	roleMenusDo

	ALL         field.Asterisk
	ID          field.Int64
	RoleID      field.Int64
	MenuID      field.Int64
	CreatedUser field.String
	UpdatedUser field.String
	CreatedAt   field.Time
	UpdatedAt   field.Time

	fieldMap map[string]field.Expr
}

func (r roleMenus) Table(newTableName string) *roleMenus {
	r.roleMenusDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

func (r roleMenus) As(alias string) *roleMenus {
	r.roleMenusDo.DO = *(r.roleMenusDo.As(alias).(*gen.DO))
	return r.updateTableName(alias)
}

func (r *roleMenus) updateTableName(table string) *roleMenus {
	r.ALL = field.NewAsterisk(table)
	r.ID = field.NewInt64(table, "id")
	r.RoleID = field.NewInt64(table, "role_id")
	r.MenuID = field.NewInt64(table, "menu_id")
	r.CreatedUser = field.NewString(table, "created_user")
	r.UpdatedUser = field.NewString(table, "updated_user")
	r.CreatedAt = field.NewTime(table, "created_at")
	r.UpdatedAt = field.NewTime(table, "updated_at")

	r.fillFieldMap()

	return r
}

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

func (r *roleMenus) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 7)
	r.fieldMap["id"] = r.ID
	r.fieldMap["role_id"] = r.RoleID
	r.fieldMap["menu_id"] = r.MenuID
	r.fieldMap["created_user"] = r.CreatedUser
	r.fieldMap["updated_user"] = r.UpdatedUser
	r.fieldMap["created_at"] = r.CreatedAt
	r.fieldMap["updated_at"] = r.UpdatedAt
}

func (r roleMenus) clone(db *gorm.DB) roleMenus {
	r.roleMenusDo.ReplaceConnPool(db.Statement.ConnPool)
	return r
}

func (r roleMenus) replaceDB(db *gorm.DB) roleMenus {
	r.roleMenusDo.ReplaceDB(db)
	return r
}

type roleMenusDo struct{ gen.DO }

func (r roleMenusDo) Debug() *roleMenusDo {
	return r.withDO(r.DO.Debug())
}

func (r roleMenusDo) WithContext(ctx context.Context) *roleMenusDo {
	return r.withDO(r.DO.WithContext(ctx))
}

func (r roleMenusDo) ReadDB() *roleMenusDo {
	return r.Clauses(dbresolver.Read)
}

func (r roleMenusDo) WriteDB() *roleMenusDo {
	return r.Clauses(dbresolver.Write)
}

func (r roleMenusDo) Session(config *gorm.Session) *roleMenusDo {
	return r.withDO(r.DO.Session(config))
}

func (r roleMenusDo) Clauses(conds ...clause.Expression) *roleMenusDo {
	return r.withDO(r.DO.Clauses(conds...))
}

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

func (r roleMenusDo) Not(conds ...gen.Condition) *roleMenusDo {
	return r.withDO(r.DO.Not(conds...))
}

func (r roleMenusDo) Or(conds ...gen.Condition) *roleMenusDo {
	return r.withDO(r.DO.Or(conds...))
}

func (r roleMenusDo) Select(conds ...field.Expr) *roleMenusDo {
	return r.withDO(r.DO.Select(conds...))
}

func (r roleMenusDo) Where(conds ...gen.Condition) *roleMenusDo {
	return r.withDO(r.DO.Where(conds...))
}

func (r roleMenusDo) Order(conds ...field.Expr) *roleMenusDo {
	return r.withDO(r.DO.Order(conds...))
}

func (r roleMenusDo) Distinct(cols ...field.Expr) *roleMenusDo {
	return r.withDO(r.DO.Distinct(cols...))
}

func (r roleMenusDo) Omit(cols ...field.Expr) *roleMenusDo {
	return r.withDO(r.DO.Omit(cols...))
}

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

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

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

func (r roleMenusDo) Group(cols ...field.Expr) *roleMenusDo {
	return r.withDO(r.DO.Group(cols...))
}

func (r roleMenusDo) Having(conds ...gen.Condition) *roleMenusDo {
	return r.withDO(r.DO.Having(conds...))
}

func (r roleMenusDo) Limit(limit int) *roleMenusDo {
	return r.withDO(r.DO.Limit(limit))
}

func (r roleMenusDo) Offset(offset int) *roleMenusDo {
	return r.withDO(r.DO.Offset(offset))
}

func (r roleMenusDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *roleMenusDo {
	return r.withDO(r.DO.Scopes(funcs...))
}

func (r roleMenusDo) Unscoped() *roleMenusDo {
	return r.withDO(r.DO.Unscoped())
}

func (r roleMenusDo) Create(values ...*model.RoleMenus) error {
	if len(values) == 0 {
		return nil
	}
	return r.DO.Create(values)
}

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

func (r roleMenusDo) First() (*model.RoleMenus, error) {
	if result, err := r.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.RoleMenus), nil
	}
}

func (r roleMenusDo) Take() (*model.RoleMenus, error) {
	if result, err := r.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.RoleMenus), nil
	}
}

func (r roleMenusDo) Last() (*model.RoleMenus, error) {
	if result, err := r.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.RoleMenus), nil
	}
}

func (r roleMenusDo) Find() ([]*model.RoleMenus, error) {
	result, err := r.DO.Find()
	return result.([]*model.RoleMenus), err
}

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

func (r roleMenusDo) Attrs(attrs ...field.AssignExpr) *roleMenusDo {
	return r.withDO(r.DO.Attrs(attrs...))
}

func (r roleMenusDo) Assign(attrs ...field.AssignExpr) *roleMenusDo {
	return r.withDO(r.DO.Assign(attrs...))
}

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

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

func (r roleMenusDo) FirstOrInit() (*model.RoleMenus, error) {
	if result, err := r.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.RoleMenus), nil
	}
}

func (r roleMenusDo) FirstOrCreate() (*model.RoleMenus, error) {
	if result, err := r.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.RoleMenus), nil
	}
}

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

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

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

func (r roleMenusDo) Scan(result interface{}) (err error) {
	return r.DO.Scan(result)
}

func (r roleMenusDo) Delete(models ...*model.RoleMenus) (result gen.ResultInfo, err error) {
	return r.DO.Delete(models)
}

func (r *roleMenusDo) withDO(do gen.Dao) *roleMenusDo {
	r.DO = *do.(*gen.DO)
	return r
}
