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

	_menuActions.menuActionsDo.UseDB(db, opts...)
	_menuActions.menuActionsDo.UseModel(&model.MenuActions{})

	tableName := _menuActions.menuActionsDo.TableName()
	_menuActions.ALL = field.NewAsterisk(tableName)
	_menuActions.ID = field.NewInt64(tableName, "id")
	_menuActions.MenuID = field.NewInt64(tableName, "menu_id")
	_menuActions.ActionMark = field.NewString(tableName, "action_mark")
	_menuActions.ActionName = field.NewString(tableName, "action_name")
	_menuActions.Status = field.NewBool(tableName, "status")
	_menuActions.CreatedUser = field.NewString(tableName, "created_user")
	_menuActions.UpdatedUser = field.NewString(tableName, "updated_user")
	_menuActions.CreatedAt = field.NewTime(tableName, "created_at")
	_menuActions.UpdatedAt = field.NewTime(tableName, "updated_at")
	_menuActions.DeletedAt = field.NewField(tableName, "deleted_at")

	_menuActions.fillFieldMap()

	return _menuActions
}

type menuActions struct {
	menuActionsDo

	ALL         field.Asterisk
	ID          field.Int64
	MenuID      field.Int64
	ActionMark  field.String
	ActionName  field.String
	Status      field.Bool
	CreatedUser field.String
	UpdatedUser field.String
	CreatedAt   field.Time
	UpdatedAt   field.Time
	DeletedAt   field.Field

	fieldMap map[string]field.Expr
}

func (m menuActions) Table(newTableName string) *menuActions {
	m.menuActionsDo.UseTable(newTableName)
	return m.updateTableName(newTableName)
}

func (m menuActions) As(alias string) *menuActions {
	m.menuActionsDo.DO = *(m.menuActionsDo.As(alias).(*gen.DO))
	return m.updateTableName(alias)
}

func (m *menuActions) updateTableName(table string) *menuActions {
	m.ALL = field.NewAsterisk(table)
	m.ID = field.NewInt64(table, "id")
	m.MenuID = field.NewInt64(table, "menu_id")
	m.ActionMark = field.NewString(table, "action_mark")
	m.ActionName = field.NewString(table, "action_name")
	m.Status = field.NewBool(table, "status")
	m.CreatedUser = field.NewString(table, "created_user")
	m.UpdatedUser = field.NewString(table, "updated_user")
	m.CreatedAt = field.NewTime(table, "created_at")
	m.UpdatedAt = field.NewTime(table, "updated_at")
	m.DeletedAt = field.NewField(table, "deleted_at")

	m.fillFieldMap()

	return m
}

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

func (m *menuActions) fillFieldMap() {
	m.fieldMap = make(map[string]field.Expr, 10)
	m.fieldMap["id"] = m.ID
	m.fieldMap["menu_id"] = m.MenuID
	m.fieldMap["action_mark"] = m.ActionMark
	m.fieldMap["action_name"] = m.ActionName
	m.fieldMap["status"] = m.Status
	m.fieldMap["created_user"] = m.CreatedUser
	m.fieldMap["updated_user"] = m.UpdatedUser
	m.fieldMap["created_at"] = m.CreatedAt
	m.fieldMap["updated_at"] = m.UpdatedAt
	m.fieldMap["deleted_at"] = m.DeletedAt
}

func (m menuActions) clone(db *gorm.DB) menuActions {
	m.menuActionsDo.ReplaceConnPool(db.Statement.ConnPool)
	return m
}

func (m menuActions) replaceDB(db *gorm.DB) menuActions {
	m.menuActionsDo.ReplaceDB(db)
	return m
}

type menuActionsDo struct{ gen.DO }

func (m menuActionsDo) Debug() *menuActionsDo {
	return m.withDO(m.DO.Debug())
}

func (m menuActionsDo) WithContext(ctx context.Context) *menuActionsDo {
	return m.withDO(m.DO.WithContext(ctx))
}

func (m menuActionsDo) ReadDB() *menuActionsDo {
	return m.Clauses(dbresolver.Read)
}

func (m menuActionsDo) WriteDB() *menuActionsDo {
	return m.Clauses(dbresolver.Write)
}

func (m menuActionsDo) Session(config *gorm.Session) *menuActionsDo {
	return m.withDO(m.DO.Session(config))
}

func (m menuActionsDo) Clauses(conds ...clause.Expression) *menuActionsDo {
	return m.withDO(m.DO.Clauses(conds...))
}

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

func (m menuActionsDo) Not(conds ...gen.Condition) *menuActionsDo {
	return m.withDO(m.DO.Not(conds...))
}

func (m menuActionsDo) Or(conds ...gen.Condition) *menuActionsDo {
	return m.withDO(m.DO.Or(conds...))
}

func (m menuActionsDo) Select(conds ...field.Expr) *menuActionsDo {
	return m.withDO(m.DO.Select(conds...))
}

func (m menuActionsDo) Where(conds ...gen.Condition) *menuActionsDo {
	return m.withDO(m.DO.Where(conds...))
}

func (m menuActionsDo) Order(conds ...field.Expr) *menuActionsDo {
	return m.withDO(m.DO.Order(conds...))
}

func (m menuActionsDo) Distinct(cols ...field.Expr) *menuActionsDo {
	return m.withDO(m.DO.Distinct(cols...))
}

func (m menuActionsDo) Omit(cols ...field.Expr) *menuActionsDo {
	return m.withDO(m.DO.Omit(cols...))
}

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

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

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

func (m menuActionsDo) Group(cols ...field.Expr) *menuActionsDo {
	return m.withDO(m.DO.Group(cols...))
}

func (m menuActionsDo) Having(conds ...gen.Condition) *menuActionsDo {
	return m.withDO(m.DO.Having(conds...))
}

func (m menuActionsDo) Limit(limit int) *menuActionsDo {
	return m.withDO(m.DO.Limit(limit))
}

func (m menuActionsDo) Offset(offset int) *menuActionsDo {
	return m.withDO(m.DO.Offset(offset))
}

func (m menuActionsDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *menuActionsDo {
	return m.withDO(m.DO.Scopes(funcs...))
}

func (m menuActionsDo) Unscoped() *menuActionsDo {
	return m.withDO(m.DO.Unscoped())
}

func (m menuActionsDo) Create(values ...*model.MenuActions) error {
	if len(values) == 0 {
		return nil
	}
	return m.DO.Create(values)
}

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

func (m menuActionsDo) First() (*model.MenuActions, error) {
	if result, err := m.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.MenuActions), nil
	}
}

func (m menuActionsDo) Take() (*model.MenuActions, error) {
	if result, err := m.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.MenuActions), nil
	}
}

func (m menuActionsDo) Last() (*model.MenuActions, error) {
	if result, err := m.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.MenuActions), nil
	}
}

func (m menuActionsDo) Find() ([]*model.MenuActions, error) {
	result, err := m.DO.Find()
	return result.([]*model.MenuActions), err
}

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

func (m menuActionsDo) Attrs(attrs ...field.AssignExpr) *menuActionsDo {
	return m.withDO(m.DO.Attrs(attrs...))
}

func (m menuActionsDo) Assign(attrs ...field.AssignExpr) *menuActionsDo {
	return m.withDO(m.DO.Assign(attrs...))
}

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

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

func (m menuActionsDo) FirstOrInit() (*model.MenuActions, error) {
	if result, err := m.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.MenuActions), nil
	}
}

func (m menuActionsDo) FirstOrCreate() (*model.MenuActions, error) {
	if result, err := m.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.MenuActions), nil
	}
}

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

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

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

func (m menuActionsDo) Scan(result interface{}) (err error) {
	return m.DO.Scan(result)
}

func (m menuActionsDo) Delete(models ...*model.MenuActions) (result gen.ResultInfo, err error) {
	return m.DO.Delete(models)
}

func (m *menuActionsDo) withDO(do gen.Dao) *menuActionsDo {
	m.DO = *do.(*gen.DO)
	return m
}
