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

	_expeditionLog.expeditionLogDo.UseDB(db, opts...)
	_expeditionLog.expeditionLogDo.UseModel(&model.ExpeditionLog{})

	tableName := _expeditionLog.expeditionLogDo.TableName()
	_expeditionLog.ALL = field.NewAsterisk(tableName)
	_expeditionLog.ID = field.NewInt64(tableName, "id")
	_expeditionLog.UserID = field.NewInt64(tableName, "user_id")
	_expeditionLog.ServerID = field.NewInt32(tableName, "server_id")
	_expeditionLog.EventID = field.NewInt32(tableName, "event_id")
	_expeditionLog.Floor = field.NewInt32(tableName, "floor")
	_expeditionLog.Goods = field.NewString(tableName, "goods")
	_expeditionLog.CostType = field.NewInt32(tableName, "cost_type")
	_expeditionLog.Date = field.NewString(tableName, "date")
	_expeditionLog.EventAt = field.NewInt32(tableName, "event_at")
	_expeditionLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_expeditionLog.fillFieldMap()

	return _expeditionLog
}

type expeditionLog struct {
	expeditionLogDo

	ALL       field.Asterisk
	ID        field.Int64
	UserID    field.Int64  // 用户id
	ServerID  field.Int32  // 服务器ID
	EventID   field.Int32  // 事件ID
	Floor     field.Int32  // 关卡ID
	Goods     field.String // {id,count}—{物品id,物品数量}
	CostType  field.Int32  //  1看广告 2 钻石 3人民币
	Date      field.String // 触发日期 2005-01-02
	EventAt   field.Int32  // 触发时间戳
	EventAtNs field.Int64  // 发生时间ns

	fieldMap map[string]field.Expr
}

func (e expeditionLog) Table(newTableName string) *expeditionLog {
	e.expeditionLogDo.UseTable(newTableName)
	return e.updateTableName(newTableName)
}

func (e expeditionLog) As(alias string) *expeditionLog {
	e.expeditionLogDo.DO = *(e.expeditionLogDo.As(alias).(*gen.DO))
	return e.updateTableName(alias)
}

func (e *expeditionLog) updateTableName(table string) *expeditionLog {
	e.ALL = field.NewAsterisk(table)
	e.ID = field.NewInt64(table, "id")
	e.UserID = field.NewInt64(table, "user_id")
	e.ServerID = field.NewInt32(table, "server_id")
	e.EventID = field.NewInt32(table, "event_id")
	e.Floor = field.NewInt32(table, "floor")
	e.Goods = field.NewString(table, "goods")
	e.CostType = field.NewInt32(table, "cost_type")
	e.Date = field.NewString(table, "date")
	e.EventAt = field.NewInt32(table, "event_at")
	e.EventAtNs = field.NewInt64(table, "event_at_ns")

	e.fillFieldMap()

	return e
}

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

func (e *expeditionLog) fillFieldMap() {
	e.fieldMap = make(map[string]field.Expr, 10)
	e.fieldMap["id"] = e.ID
	e.fieldMap["user_id"] = e.UserID
	e.fieldMap["server_id"] = e.ServerID
	e.fieldMap["event_id"] = e.EventID
	e.fieldMap["floor"] = e.Floor
	e.fieldMap["goods"] = e.Goods
	e.fieldMap["cost_type"] = e.CostType
	e.fieldMap["date"] = e.Date
	e.fieldMap["event_at"] = e.EventAt
	e.fieldMap["event_at_ns"] = e.EventAtNs
}

func (e expeditionLog) clone(db *gorm.DB) expeditionLog {
	e.expeditionLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return e
}

func (e expeditionLog) replaceDB(db *gorm.DB) expeditionLog {
	e.expeditionLogDo.ReplaceDB(db)
	return e
}

type expeditionLogDo struct{ gen.DO }

func (e expeditionLogDo) Debug() *expeditionLogDo {
	return e.withDO(e.DO.Debug())
}

func (e expeditionLogDo) WithContext(ctx context.Context) *expeditionLogDo {
	return e.withDO(e.DO.WithContext(ctx))
}

func (e expeditionLogDo) ReadDB() *expeditionLogDo {
	return e.Clauses(dbresolver.Read)
}

func (e expeditionLogDo) WriteDB() *expeditionLogDo {
	return e.Clauses(dbresolver.Write)
}

func (e expeditionLogDo) Session(config *gorm.Session) *expeditionLogDo {
	return e.withDO(e.DO.Session(config))
}

func (e expeditionLogDo) Clauses(conds ...clause.Expression) *expeditionLogDo {
	return e.withDO(e.DO.Clauses(conds...))
}

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

func (e expeditionLogDo) Not(conds ...gen.Condition) *expeditionLogDo {
	return e.withDO(e.DO.Not(conds...))
}

func (e expeditionLogDo) Or(conds ...gen.Condition) *expeditionLogDo {
	return e.withDO(e.DO.Or(conds...))
}

func (e expeditionLogDo) Select(conds ...field.Expr) *expeditionLogDo {
	return e.withDO(e.DO.Select(conds...))
}

func (e expeditionLogDo) Where(conds ...gen.Condition) *expeditionLogDo {
	return e.withDO(e.DO.Where(conds...))
}

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

func (e expeditionLogDo) Order(conds ...field.Expr) *expeditionLogDo {
	return e.withDO(e.DO.Order(conds...))
}

func (e expeditionLogDo) Distinct(cols ...field.Expr) *expeditionLogDo {
	return e.withDO(e.DO.Distinct(cols...))
}

func (e expeditionLogDo) Omit(cols ...field.Expr) *expeditionLogDo {
	return e.withDO(e.DO.Omit(cols...))
}

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

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

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

func (e expeditionLogDo) Group(cols ...field.Expr) *expeditionLogDo {
	return e.withDO(e.DO.Group(cols...))
}

func (e expeditionLogDo) Having(conds ...gen.Condition) *expeditionLogDo {
	return e.withDO(e.DO.Having(conds...))
}

func (e expeditionLogDo) Limit(limit int) *expeditionLogDo {
	return e.withDO(e.DO.Limit(limit))
}

func (e expeditionLogDo) Offset(offset int) *expeditionLogDo {
	return e.withDO(e.DO.Offset(offset))
}

func (e expeditionLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *expeditionLogDo {
	return e.withDO(e.DO.Scopes(funcs...))
}

func (e expeditionLogDo) Unscoped() *expeditionLogDo {
	return e.withDO(e.DO.Unscoped())
}

func (e expeditionLogDo) Create(values ...*model.ExpeditionLog) error {
	if len(values) == 0 {
		return nil
	}
	return e.DO.Create(values)
}

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

func (e expeditionLogDo) First() (*model.ExpeditionLog, error) {
	if result, err := e.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExpeditionLog), nil
	}
}

func (e expeditionLogDo) Take() (*model.ExpeditionLog, error) {
	if result, err := e.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExpeditionLog), nil
	}
}

func (e expeditionLogDo) Last() (*model.ExpeditionLog, error) {
	if result, err := e.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExpeditionLog), nil
	}
}

func (e expeditionLogDo) Find() ([]*model.ExpeditionLog, error) {
	result, err := e.DO.Find()
	return result.([]*model.ExpeditionLog), err
}

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

func (e expeditionLogDo) Attrs(attrs ...field.AssignExpr) *expeditionLogDo {
	return e.withDO(e.DO.Attrs(attrs...))
}

func (e expeditionLogDo) Assign(attrs ...field.AssignExpr) *expeditionLogDo {
	return e.withDO(e.DO.Assign(attrs...))
}

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

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

func (e expeditionLogDo) FirstOrInit() (*model.ExpeditionLog, error) {
	if result, err := e.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExpeditionLog), nil
	}
}

func (e expeditionLogDo) FirstOrCreate() (*model.ExpeditionLog, error) {
	if result, err := e.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ExpeditionLog), nil
	}
}

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

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

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

func (e expeditionLogDo) Scan(result interface{}) (err error) {
	return e.DO.Scan(result)
}

func (e expeditionLogDo) Delete(models ...*model.ExpeditionLog) (result gen.ResultInfo, err error) {
	return e.DO.Delete(models)
}

func (e *expeditionLogDo) withDO(do gen.Dao) *expeditionLogDo {
	e.DO = *do.(*gen.DO)
	return e
}
