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

	_logOperation.logOperationDo.UseDB(db, opts...)
	_logOperation.logOperationDo.UseModel(&model.LogOperation{})

	tableName := _logOperation.logOperationDo.TableName()
	_logOperation.ALL = field.NewAsterisk(tableName)
	_logOperation.ID = field.NewInt32(tableName, "id")
	_logOperation.Level = field.NewString(tableName, "level")
	_logOperation.Msg = field.NewString(tableName, "msg")
	_logOperation.Content = field.NewString(tableName, "content")
	_logOperation.CreatedAt = field.NewTime(tableName, "created_at")

	_logOperation.fillFieldMap()

	return _logOperation
}

// logOperation 内部日志表
type logOperation struct {
	logOperationDo

	ALL       field.Asterisk
	ID        field.Int32  // 主键
	Level     field.String // 错误级别
	Msg       field.String // 错误信息
	Content   field.String // 错误内容
	CreatedAt field.Time   // 创建时间

	fieldMap map[string]field.Expr
}

func (l logOperation) Table(newTableName string) *logOperation {
	l.logOperationDo.UseTable(newTableName)
	return l.updateTableName(newTableName)
}

func (l logOperation) As(alias string) *logOperation {
	l.logOperationDo.DO = *(l.logOperationDo.As(alias).(*gen.DO))
	return l.updateTableName(alias)
}

func (l *logOperation) updateTableName(table string) *logOperation {
	l.ALL = field.NewAsterisk(table)
	l.ID = field.NewInt32(table, "id")
	l.Level = field.NewString(table, "level")
	l.Msg = field.NewString(table, "msg")
	l.Content = field.NewString(table, "content")
	l.CreatedAt = field.NewTime(table, "created_at")

	l.fillFieldMap()

	return l
}

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

func (l *logOperation) fillFieldMap() {
	l.fieldMap = make(map[string]field.Expr, 5)
	l.fieldMap["id"] = l.ID
	l.fieldMap["level"] = l.Level
	l.fieldMap["msg"] = l.Msg
	l.fieldMap["content"] = l.Content
	l.fieldMap["created_at"] = l.CreatedAt
}

func (l logOperation) clone(db *gorm.DB) logOperation {
	l.logOperationDo.ReplaceConnPool(db.Statement.ConnPool)
	return l
}

func (l logOperation) replaceDB(db *gorm.DB) logOperation {
	l.logOperationDo.ReplaceDB(db)
	return l
}

type logOperationDo struct{ gen.DO }

func (l logOperationDo) Debug() *logOperationDo {
	return l.withDO(l.DO.Debug())
}

func (l logOperationDo) WithContext(ctx context.Context) *logOperationDo {
	return l.withDO(l.DO.WithContext(ctx))
}

func (l logOperationDo) ReadDB() *logOperationDo {
	return l.Clauses(dbresolver.Read)
}

func (l logOperationDo) WriteDB() *logOperationDo {
	return l.Clauses(dbresolver.Write)
}

func (l logOperationDo) Session(config *gorm.Session) *logOperationDo {
	return l.withDO(l.DO.Session(config))
}

func (l logOperationDo) Clauses(conds ...clause.Expression) *logOperationDo {
	return l.withDO(l.DO.Clauses(conds...))
}

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

func (l logOperationDo) Not(conds ...gen.Condition) *logOperationDo {
	return l.withDO(l.DO.Not(conds...))
}

func (l logOperationDo) Or(conds ...gen.Condition) *logOperationDo {
	return l.withDO(l.DO.Or(conds...))
}

func (l logOperationDo) Select(conds ...field.Expr) *logOperationDo {
	return l.withDO(l.DO.Select(conds...))
}

func (l logOperationDo) Where(conds ...gen.Condition) *logOperationDo {
	return l.withDO(l.DO.Where(conds...))
}

func (l logOperationDo) Order(conds ...field.Expr) *logOperationDo {
	return l.withDO(l.DO.Order(conds...))
}

func (l logOperationDo) Distinct(cols ...field.Expr) *logOperationDo {
	return l.withDO(l.DO.Distinct(cols...))
}

func (l logOperationDo) Omit(cols ...field.Expr) *logOperationDo {
	return l.withDO(l.DO.Omit(cols...))
}

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

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

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

func (l logOperationDo) Group(cols ...field.Expr) *logOperationDo {
	return l.withDO(l.DO.Group(cols...))
}

func (l logOperationDo) Having(conds ...gen.Condition) *logOperationDo {
	return l.withDO(l.DO.Having(conds...))
}

func (l logOperationDo) Limit(limit int) *logOperationDo {
	return l.withDO(l.DO.Limit(limit))
}

func (l logOperationDo) Offset(offset int) *logOperationDo {
	return l.withDO(l.DO.Offset(offset))
}

func (l logOperationDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *logOperationDo {
	return l.withDO(l.DO.Scopes(funcs...))
}

func (l logOperationDo) Unscoped() *logOperationDo {
	return l.withDO(l.DO.Unscoped())
}

func (l logOperationDo) Create(values ...*model.LogOperation) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Create(values)
}

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

func (l logOperationDo) First() (*model.LogOperation, error) {
	if result, err := l.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.LogOperation), nil
	}
}

func (l logOperationDo) Take() (*model.LogOperation, error) {
	if result, err := l.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.LogOperation), nil
	}
}

func (l logOperationDo) Last() (*model.LogOperation, error) {
	if result, err := l.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.LogOperation), nil
	}
}

func (l logOperationDo) Find() ([]*model.LogOperation, error) {
	result, err := l.DO.Find()
	return result.([]*model.LogOperation), err
}

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

func (l logOperationDo) Attrs(attrs ...field.AssignExpr) *logOperationDo {
	return l.withDO(l.DO.Attrs(attrs...))
}

func (l logOperationDo) Assign(attrs ...field.AssignExpr) *logOperationDo {
	return l.withDO(l.DO.Assign(attrs...))
}

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

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

func (l logOperationDo) FirstOrInit() (*model.LogOperation, error) {
	if result, err := l.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.LogOperation), nil
	}
}

func (l logOperationDo) FirstOrCreate() (*model.LogOperation, error) {
	if result, err := l.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.LogOperation), nil
	}
}

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

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

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

func (l logOperationDo) Scan(result interface{}) (err error) {
	return l.DO.Scan(result)
}

func (l logOperationDo) Delete(models ...*model.LogOperation) (result gen.ResultInfo, err error) {
	return l.DO.Delete(models)
}

func (l *logOperationDo) withDO(do gen.Dao) *logOperationDo {
	l.DO = *do.(*gen.DO)
	return l
}
