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

	_gudongLog.gudongLogDo.UseDB(db, opts...)
	_gudongLog.gudongLogDo.UseModel(&model.GudongLog{})

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

	_gudongLog.fillFieldMap()

	return _gudongLog
}

type gudongLog struct {
	gudongLogDo

	ALL           field.Asterisk
	ID            field.Int64
	UserID        field.Int64  // 用户id
	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.Int64  // 获取银币数量
	Date          field.String // 触发日期 2005-01-02
	UserCreatedAt field.Int32
	EventAtNs     field.Int64 // 发生时间ns

	fieldMap map[string]field.Expr
}

func (g gudongLog) Table(newTableName string) *gudongLog {
	g.gudongLogDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

func (g gudongLog) As(alias string) *gudongLog {
	g.gudongLogDo.DO = *(g.gudongLogDo.As(alias).(*gen.DO))
	return g.updateTableName(alias)
}

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

	g.fillFieldMap()

	return g
}

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

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

func (g gudongLog) clone(db *gorm.DB) gudongLog {
	g.gudongLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return g
}

func (g gudongLog) replaceDB(db *gorm.DB) gudongLog {
	g.gudongLogDo.ReplaceDB(db)
	return g
}

type gudongLogDo struct{ gen.DO }

func (g gudongLogDo) Debug() *gudongLogDo {
	return g.withDO(g.DO.Debug())
}

func (g gudongLogDo) WithContext(ctx context.Context) *gudongLogDo {
	return g.withDO(g.DO.WithContext(ctx))
}

func (g gudongLogDo) ReadDB() *gudongLogDo {
	return g.Clauses(dbresolver.Read)
}

func (g gudongLogDo) WriteDB() *gudongLogDo {
	return g.Clauses(dbresolver.Write)
}

func (g gudongLogDo) Session(config *gorm.Session) *gudongLogDo {
	return g.withDO(g.DO.Session(config))
}

func (g gudongLogDo) Clauses(conds ...clause.Expression) *gudongLogDo {
	return g.withDO(g.DO.Clauses(conds...))
}

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

func (g gudongLogDo) Not(conds ...gen.Condition) *gudongLogDo {
	return g.withDO(g.DO.Not(conds...))
}

func (g gudongLogDo) Or(conds ...gen.Condition) *gudongLogDo {
	return g.withDO(g.DO.Or(conds...))
}

func (g gudongLogDo) Select(conds ...field.Expr) *gudongLogDo {
	return g.withDO(g.DO.Select(conds...))
}

func (g gudongLogDo) Where(conds ...gen.Condition) *gudongLogDo {
	return g.withDO(g.DO.Where(conds...))
}

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

func (g gudongLogDo) Order(conds ...field.Expr) *gudongLogDo {
	return g.withDO(g.DO.Order(conds...))
}

func (g gudongLogDo) Distinct(cols ...field.Expr) *gudongLogDo {
	return g.withDO(g.DO.Distinct(cols...))
}

func (g gudongLogDo) Omit(cols ...field.Expr) *gudongLogDo {
	return g.withDO(g.DO.Omit(cols...))
}

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

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

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

func (g gudongLogDo) Group(cols ...field.Expr) *gudongLogDo {
	return g.withDO(g.DO.Group(cols...))
}

func (g gudongLogDo) Having(conds ...gen.Condition) *gudongLogDo {
	return g.withDO(g.DO.Having(conds...))
}

func (g gudongLogDo) Limit(limit int) *gudongLogDo {
	return g.withDO(g.DO.Limit(limit))
}

func (g gudongLogDo) Offset(offset int) *gudongLogDo {
	return g.withDO(g.DO.Offset(offset))
}

func (g gudongLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gudongLogDo {
	return g.withDO(g.DO.Scopes(funcs...))
}

func (g gudongLogDo) Unscoped() *gudongLogDo {
	return g.withDO(g.DO.Unscoped())
}

func (g gudongLogDo) Create(values ...*model.GudongLog) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Create(values)
}

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

func (g gudongLogDo) First() (*model.GudongLog, error) {
	if result, err := g.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.GudongLog), nil
	}
}

func (g gudongLogDo) Take() (*model.GudongLog, error) {
	if result, err := g.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.GudongLog), nil
	}
}

func (g gudongLogDo) Last() (*model.GudongLog, error) {
	if result, err := g.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.GudongLog), nil
	}
}

func (g gudongLogDo) Find() ([]*model.GudongLog, error) {
	result, err := g.DO.Find()
	return result.([]*model.GudongLog), err
}

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

func (g gudongLogDo) Attrs(attrs ...field.AssignExpr) *gudongLogDo {
	return g.withDO(g.DO.Attrs(attrs...))
}

func (g gudongLogDo) Assign(attrs ...field.AssignExpr) *gudongLogDo {
	return g.withDO(g.DO.Assign(attrs...))
}

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

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

func (g gudongLogDo) FirstOrInit() (*model.GudongLog, error) {
	if result, err := g.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.GudongLog), nil
	}
}

func (g gudongLogDo) FirstOrCreate() (*model.GudongLog, error) {
	if result, err := g.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.GudongLog), nil
	}
}

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

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

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

func (g gudongLogDo) Scan(result interface{}) (err error) {
	return g.DO.Scan(result)
}

func (g gudongLogDo) Delete(models ...*model.GudongLog) (result gen.ResultInfo, err error) {
	return g.DO.Delete(models)
}

func (g *gudongLogDo) withDO(do gen.Dao) *gudongLogDo {
	g.DO = *do.(*gen.DO)
	return g
}
