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

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

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

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newTestLog(db *gorm.DB, opts ...gen.DOOption) testLog {
	_testLog := testLog{}

	_testLog.testLogDo.UseDB(db, opts...)
	_testLog.testLogDo.UseModel(&model.TestLog{})

	tableName := _testLog.testLogDo.TableName()
	_testLog.ALL = field.NewAsterisk(tableName)
	_testLog.ID = field.NewInt64(tableName, "id")
	_testLog.UserID = field.NewInt64(tableName, "user_id")
	_testLog.ServerID = field.NewInt32(tableName, "server_id")
	_testLog.EventID = field.NewInt32(tableName, "event_id")
	_testLog.EventAt = field.NewInt32(tableName, "event_at")
	_testLog.BoxType = field.NewInt32(tableName, "box_type")
	_testLog.CostType = field.NewInt32(tableName, "cost_type")
	_testLog.GoodsID = field.NewInt32(tableName, "goods_id")
	_testLog.Level = field.NewInt32(tableName, "level")
	_testLog.Amount = field.NewInt32(tableName, "amount")
	_testLog.Date = field.NewString(tableName, "date")
	_testLog.UserCreatedAt = field.NewInt32(tableName, "user_created_at")
	_testLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_testLog.fillFieldMap()

	return _testLog
}

type testLog struct {
	testLogDo

	ALL           field.Asterisk
	ID            field.Int64
	UserID        field.Int64
	ServerID      field.Int32  // 服务器ID
	EventID       field.Int32  // 1 进入 2 离开 3 获得精力 4 获得钻石 5 获得物品 6 加速元素宝匣 7 出售物品 8 合成物品 9 古玩鉴定 10 古玩升级 11 获得展览收益 12 兑换物品 13 查看排行榜 14 查看排行榜奖励
	EventAt       field.Int32  // 触发时间戳
	BoxType       field.Int32  // 宝匣类型 1金 2木 3水 4火 5土
	CostType      field.Int32  //  1看广告 2 钻石 3人民币
	GoodsID       field.Int32  // 古玩id，物品id
	Level         field.Int32  // 玩家升级后等级
	Amount        field.Int32  // 获取银币数量
	Date          field.String // 触发日期 2005-01-02
	UserCreatedAt field.Int32
	EventAtNs     field.Int64 // 发生时间ns

	fieldMap map[string]field.Expr
}

func (t testLog) Table(newTableName string) *testLog {
	t.testLogDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

func (t testLog) As(alias string) *testLog {
	t.testLogDo.DO = *(t.testLogDo.As(alias).(*gen.DO))
	return t.updateTableName(alias)
}

func (t *testLog) updateTableName(table string) *testLog {
	t.ALL = field.NewAsterisk(table)
	t.ID = field.NewInt64(table, "id")
	t.UserID = field.NewInt64(table, "user_id")
	t.ServerID = field.NewInt32(table, "server_id")
	t.EventID = field.NewInt32(table, "event_id")
	t.EventAt = field.NewInt32(table, "event_at")
	t.BoxType = field.NewInt32(table, "box_type")
	t.CostType = field.NewInt32(table, "cost_type")
	t.GoodsID = field.NewInt32(table, "goods_id")
	t.Level = field.NewInt32(table, "level")
	t.Amount = field.NewInt32(table, "amount")
	t.Date = field.NewString(table, "date")
	t.UserCreatedAt = field.NewInt32(table, "user_created_at")
	t.EventAtNs = field.NewInt64(table, "event_at_ns")

	t.fillFieldMap()

	return t
}

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

func (t *testLog) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 13)
	t.fieldMap["id"] = t.ID
	t.fieldMap["user_id"] = t.UserID
	t.fieldMap["server_id"] = t.ServerID
	t.fieldMap["event_id"] = t.EventID
	t.fieldMap["event_at"] = t.EventAt
	t.fieldMap["box_type"] = t.BoxType
	t.fieldMap["cost_type"] = t.CostType
	t.fieldMap["goods_id"] = t.GoodsID
	t.fieldMap["level"] = t.Level
	t.fieldMap["amount"] = t.Amount
	t.fieldMap["date"] = t.Date
	t.fieldMap["user_created_at"] = t.UserCreatedAt
	t.fieldMap["event_at_ns"] = t.EventAtNs
}

func (t testLog) clone(db *gorm.DB) testLog {
	t.testLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return t
}

func (t testLog) replaceDB(db *gorm.DB) testLog {
	t.testLogDo.ReplaceDB(db)
	return t
}

type testLogDo struct{ gen.DO }

func (t testLogDo) Debug() *testLogDo {
	return t.withDO(t.DO.Debug())
}

func (t testLogDo) WithContext(ctx context.Context) *testLogDo {
	return t.withDO(t.DO.WithContext(ctx))
}

func (t testLogDo) ReadDB() *testLogDo {
	return t.Clauses(dbresolver.Read)
}

func (t testLogDo) WriteDB() *testLogDo {
	return t.Clauses(dbresolver.Write)
}

func (t testLogDo) Session(config *gorm.Session) *testLogDo {
	return t.withDO(t.DO.Session(config))
}

func (t testLogDo) Clauses(conds ...clause.Expression) *testLogDo {
	return t.withDO(t.DO.Clauses(conds...))
}

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

func (t testLogDo) Not(conds ...gen.Condition) *testLogDo {
	return t.withDO(t.DO.Not(conds...))
}

func (t testLogDo) Or(conds ...gen.Condition) *testLogDo {
	return t.withDO(t.DO.Or(conds...))
}

func (t testLogDo) Select(conds ...field.Expr) *testLogDo {
	return t.withDO(t.DO.Select(conds...))
}

func (t testLogDo) Where(conds ...gen.Condition) *testLogDo {
	return t.withDO(t.DO.Where(conds...))
}

func (t testLogDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *testLogDo {
	return t.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (t testLogDo) Order(conds ...field.Expr) *testLogDo {
	return t.withDO(t.DO.Order(conds...))
}

func (t testLogDo) Distinct(cols ...field.Expr) *testLogDo {
	return t.withDO(t.DO.Distinct(cols...))
}

func (t testLogDo) Omit(cols ...field.Expr) *testLogDo {
	return t.withDO(t.DO.Omit(cols...))
}

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

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

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

func (t testLogDo) Group(cols ...field.Expr) *testLogDo {
	return t.withDO(t.DO.Group(cols...))
}

func (t testLogDo) Having(conds ...gen.Condition) *testLogDo {
	return t.withDO(t.DO.Having(conds...))
}

func (t testLogDo) Limit(limit int) *testLogDo {
	return t.withDO(t.DO.Limit(limit))
}

func (t testLogDo) Offset(offset int) *testLogDo {
	return t.withDO(t.DO.Offset(offset))
}

func (t testLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *testLogDo {
	return t.withDO(t.DO.Scopes(funcs...))
}

func (t testLogDo) Unscoped() *testLogDo {
	return t.withDO(t.DO.Unscoped())
}

func (t testLogDo) Create(values ...*model.TestLog) error {
	if len(values) == 0 {
		return nil
	}
	return t.DO.Create(values)
}

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

func (t testLogDo) First() (*model.TestLog, error) {
	if result, err := t.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.TestLog), nil
	}
}

func (t testLogDo) Take() (*model.TestLog, error) {
	if result, err := t.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.TestLog), nil
	}
}

func (t testLogDo) Last() (*model.TestLog, error) {
	if result, err := t.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.TestLog), nil
	}
}

func (t testLogDo) Find() ([]*model.TestLog, error) {
	result, err := t.DO.Find()
	return result.([]*model.TestLog), err
}

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

func (t testLogDo) Attrs(attrs ...field.AssignExpr) *testLogDo {
	return t.withDO(t.DO.Attrs(attrs...))
}

func (t testLogDo) Assign(attrs ...field.AssignExpr) *testLogDo {
	return t.withDO(t.DO.Assign(attrs...))
}

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

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

func (t testLogDo) FirstOrInit() (*model.TestLog, error) {
	if result, err := t.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.TestLog), nil
	}
}

func (t testLogDo) FirstOrCreate() (*model.TestLog, error) {
	if result, err := t.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.TestLog), nil
	}
}

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

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

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

func (t testLogDo) Scan(result interface{}) (err error) {
	return t.DO.Scan(result)
}

func (t testLogDo) Delete(models ...*model.TestLog) (result gen.ResultInfo, err error) {
	return t.DO.Delete(models)
}

func (t *testLogDo) withDO(do gen.Dao) *testLogDo {
	t.DO = *do.(*gen.DO)
	return t
}
