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

	_firstAdvLog.firstAdvLogDo.UseDB(db, opts...)
	_firstAdvLog.firstAdvLogDo.UseModel(&model.FirstAdvLog{})

	tableName := _firstAdvLog.firstAdvLogDo.TableName()
	_firstAdvLog.ALL = field.NewAsterisk(tableName)
	_firstAdvLog.ID = field.NewInt64(tableName, "id")
	_firstAdvLog.Userid = field.NewInt64(tableName, "userid")
	_firstAdvLog.ServerID = field.NewInt32(tableName, "server_id")
	_firstAdvLog.EventID = field.NewInt32(tableName, "event_id")
	_firstAdvLog.Date = field.NewString(tableName, "date")
	_firstAdvLog.EventAt = field.NewInt32(tableName, "event_at")
	_firstAdvLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_firstAdvLog.fillFieldMap()

	return _firstAdvLog
}

type firstAdvLog struct {
	firstAdvLogDo

	ALL       field.Asterisk
	ID        field.Int64
	Userid    field.Int64 // 用户ID
	ServerID  field.Int32 // 服务器ID
	EventID   field.Int32 // 事件ID
	Date      field.String
	EventAt   field.Int32 // 触发时间戳
	EventAtNs field.Int64 // 发生时间ns

	fieldMap map[string]field.Expr
}

func (f firstAdvLog) Table(newTableName string) *firstAdvLog {
	f.firstAdvLogDo.UseTable(newTableName)
	return f.updateTableName(newTableName)
}

func (f firstAdvLog) As(alias string) *firstAdvLog {
	f.firstAdvLogDo.DO = *(f.firstAdvLogDo.As(alias).(*gen.DO))
	return f.updateTableName(alias)
}

func (f *firstAdvLog) updateTableName(table string) *firstAdvLog {
	f.ALL = field.NewAsterisk(table)
	f.ID = field.NewInt64(table, "id")
	f.Userid = field.NewInt64(table, "userid")
	f.ServerID = field.NewInt32(table, "server_id")
	f.EventID = field.NewInt32(table, "event_id")
	f.Date = field.NewString(table, "date")
	f.EventAt = field.NewInt32(table, "event_at")
	f.EventAtNs = field.NewInt64(table, "event_at_ns")

	f.fillFieldMap()

	return f
}

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

func (f *firstAdvLog) fillFieldMap() {
	f.fieldMap = make(map[string]field.Expr, 7)
	f.fieldMap["id"] = f.ID
	f.fieldMap["userid"] = f.Userid
	f.fieldMap["server_id"] = f.ServerID
	f.fieldMap["event_id"] = f.EventID
	f.fieldMap["date"] = f.Date
	f.fieldMap["event_at"] = f.EventAt
	f.fieldMap["event_at_ns"] = f.EventAtNs
}

func (f firstAdvLog) clone(db *gorm.DB) firstAdvLog {
	f.firstAdvLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return f
}

func (f firstAdvLog) replaceDB(db *gorm.DB) firstAdvLog {
	f.firstAdvLogDo.ReplaceDB(db)
	return f
}

type firstAdvLogDo struct{ gen.DO }

func (f firstAdvLogDo) Debug() *firstAdvLogDo {
	return f.withDO(f.DO.Debug())
}

func (f firstAdvLogDo) WithContext(ctx context.Context) *firstAdvLogDo {
	return f.withDO(f.DO.WithContext(ctx))
}

func (f firstAdvLogDo) ReadDB() *firstAdvLogDo {
	return f.Clauses(dbresolver.Read)
}

func (f firstAdvLogDo) WriteDB() *firstAdvLogDo {
	return f.Clauses(dbresolver.Write)
}

func (f firstAdvLogDo) Session(config *gorm.Session) *firstAdvLogDo {
	return f.withDO(f.DO.Session(config))
}

func (f firstAdvLogDo) Clauses(conds ...clause.Expression) *firstAdvLogDo {
	return f.withDO(f.DO.Clauses(conds...))
}

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

func (f firstAdvLogDo) Not(conds ...gen.Condition) *firstAdvLogDo {
	return f.withDO(f.DO.Not(conds...))
}

func (f firstAdvLogDo) Or(conds ...gen.Condition) *firstAdvLogDo {
	return f.withDO(f.DO.Or(conds...))
}

func (f firstAdvLogDo) Select(conds ...field.Expr) *firstAdvLogDo {
	return f.withDO(f.DO.Select(conds...))
}

func (f firstAdvLogDo) Where(conds ...gen.Condition) *firstAdvLogDo {
	return f.withDO(f.DO.Where(conds...))
}

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

func (f firstAdvLogDo) Order(conds ...field.Expr) *firstAdvLogDo {
	return f.withDO(f.DO.Order(conds...))
}

func (f firstAdvLogDo) Distinct(cols ...field.Expr) *firstAdvLogDo {
	return f.withDO(f.DO.Distinct(cols...))
}

func (f firstAdvLogDo) Omit(cols ...field.Expr) *firstAdvLogDo {
	return f.withDO(f.DO.Omit(cols...))
}

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

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

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

func (f firstAdvLogDo) Group(cols ...field.Expr) *firstAdvLogDo {
	return f.withDO(f.DO.Group(cols...))
}

func (f firstAdvLogDo) Having(conds ...gen.Condition) *firstAdvLogDo {
	return f.withDO(f.DO.Having(conds...))
}

func (f firstAdvLogDo) Limit(limit int) *firstAdvLogDo {
	return f.withDO(f.DO.Limit(limit))
}

func (f firstAdvLogDo) Offset(offset int) *firstAdvLogDo {
	return f.withDO(f.DO.Offset(offset))
}

func (f firstAdvLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *firstAdvLogDo {
	return f.withDO(f.DO.Scopes(funcs...))
}

func (f firstAdvLogDo) Unscoped() *firstAdvLogDo {
	return f.withDO(f.DO.Unscoped())
}

func (f firstAdvLogDo) Create(values ...*model.FirstAdvLog) error {
	if len(values) == 0 {
		return nil
	}
	return f.DO.Create(values)
}

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

func (f firstAdvLogDo) First() (*model.FirstAdvLog, error) {
	if result, err := f.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.FirstAdvLog), nil
	}
}

func (f firstAdvLogDo) Take() (*model.FirstAdvLog, error) {
	if result, err := f.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.FirstAdvLog), nil
	}
}

func (f firstAdvLogDo) Last() (*model.FirstAdvLog, error) {
	if result, err := f.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.FirstAdvLog), nil
	}
}

func (f firstAdvLogDo) Find() ([]*model.FirstAdvLog, error) {
	result, err := f.DO.Find()
	return result.([]*model.FirstAdvLog), err
}

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

func (f firstAdvLogDo) Attrs(attrs ...field.AssignExpr) *firstAdvLogDo {
	return f.withDO(f.DO.Attrs(attrs...))
}

func (f firstAdvLogDo) Assign(attrs ...field.AssignExpr) *firstAdvLogDo {
	return f.withDO(f.DO.Assign(attrs...))
}

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

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

func (f firstAdvLogDo) FirstOrInit() (*model.FirstAdvLog, error) {
	if result, err := f.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.FirstAdvLog), nil
	}
}

func (f firstAdvLogDo) FirstOrCreate() (*model.FirstAdvLog, error) {
	if result, err := f.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.FirstAdvLog), nil
	}
}

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

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

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

func (f firstAdvLogDo) Scan(result interface{}) (err error) {
	return f.DO.Scan(result)
}

func (f firstAdvLogDo) Delete(models ...*model.FirstAdvLog) (result gen.ResultInfo, err error) {
	return f.DO.Delete(models)
}

func (f *firstAdvLogDo) withDO(do gen.Dao) *firstAdvLogDo {
	f.DO = *do.(*gen.DO)
	return f
}
