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

	_abnormalPaymentLog.abnormalPaymentLogDo.UseDB(db, opts...)
	_abnormalPaymentLog.abnormalPaymentLogDo.UseModel(&model.AbnormalPaymentLog{})

	tableName := _abnormalPaymentLog.abnormalPaymentLogDo.TableName()
	_abnormalPaymentLog.ALL = field.NewAsterisk(tableName)
	_abnormalPaymentLog.ID = field.NewInt64(tableName, "id")
	_abnormalPaymentLog.UserID = field.NewInt64(tableName, "user_id")
	_abnormalPaymentLog.ServerID = field.NewInt32(tableName, "server_id")
	_abnormalPaymentLog.EventID = field.NewInt32(tableName, "event_id")
	_abnormalPaymentLog.Extra = field.NewString(tableName, "extra")
	_abnormalPaymentLog.Date = field.NewTime(tableName, "date")
	_abnormalPaymentLog.EventAt = field.NewInt32(tableName, "event_at")
	_abnormalPaymentLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_abnormalPaymentLog.fillFieldMap()

	return _abnormalPaymentLog
}

type abnormalPaymentLog struct {
	abnormalPaymentLogDo

	ALL       field.Asterisk
	ID        field.Int64
	UserID    field.Int64  // 用户ID
	ServerID  field.Int32  // 服务器ID
	EventID   field.Int32  // 事件ID
	Extra     field.String // 支付参数
	Date      field.Time   // 触发日期 2005-01-02
	EventAt   field.Int32  // 触发时间戳
	EventAtNs field.Int64  // 发生时间ns

	fieldMap map[string]field.Expr
}

func (a abnormalPaymentLog) Table(newTableName string) *abnormalPaymentLog {
	a.abnormalPaymentLogDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a abnormalPaymentLog) As(alias string) *abnormalPaymentLog {
	a.abnormalPaymentLogDo.DO = *(a.abnormalPaymentLogDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *abnormalPaymentLog) updateTableName(table string) *abnormalPaymentLog {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.UserID = field.NewInt64(table, "user_id")
	a.ServerID = field.NewInt32(table, "server_id")
	a.EventID = field.NewInt32(table, "event_id")
	a.Extra = field.NewString(table, "extra")
	a.Date = field.NewTime(table, "date")
	a.EventAt = field.NewInt32(table, "event_at")
	a.EventAtNs = field.NewInt64(table, "event_at_ns")

	a.fillFieldMap()

	return a
}

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

func (a *abnormalPaymentLog) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 8)
	a.fieldMap["id"] = a.ID
	a.fieldMap["user_id"] = a.UserID
	a.fieldMap["server_id"] = a.ServerID
	a.fieldMap["event_id"] = a.EventID
	a.fieldMap["extra"] = a.Extra
	a.fieldMap["date"] = a.Date
	a.fieldMap["event_at"] = a.EventAt
	a.fieldMap["event_at_ns"] = a.EventAtNs
}

func (a abnormalPaymentLog) clone(db *gorm.DB) abnormalPaymentLog {
	a.abnormalPaymentLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a abnormalPaymentLog) replaceDB(db *gorm.DB) abnormalPaymentLog {
	a.abnormalPaymentLogDo.ReplaceDB(db)
	return a
}

type abnormalPaymentLogDo struct{ gen.DO }

func (a abnormalPaymentLogDo) Debug() *abnormalPaymentLogDo {
	return a.withDO(a.DO.Debug())
}

func (a abnormalPaymentLogDo) WithContext(ctx context.Context) *abnormalPaymentLogDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a abnormalPaymentLogDo) ReadDB() *abnormalPaymentLogDo {
	return a.Clauses(dbresolver.Read)
}

func (a abnormalPaymentLogDo) WriteDB() *abnormalPaymentLogDo {
	return a.Clauses(dbresolver.Write)
}

func (a abnormalPaymentLogDo) Session(config *gorm.Session) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Session(config))
}

func (a abnormalPaymentLogDo) Clauses(conds ...clause.Expression) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a abnormalPaymentLogDo) Not(conds ...gen.Condition) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a abnormalPaymentLogDo) Or(conds ...gen.Condition) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a abnormalPaymentLogDo) Select(conds ...field.Expr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a abnormalPaymentLogDo) Where(conds ...gen.Condition) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Where(conds...))
}

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

func (a abnormalPaymentLogDo) Order(conds ...field.Expr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a abnormalPaymentLogDo) Distinct(cols ...field.Expr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a abnormalPaymentLogDo) Omit(cols ...field.Expr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a abnormalPaymentLogDo) Group(cols ...field.Expr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a abnormalPaymentLogDo) Having(conds ...gen.Condition) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a abnormalPaymentLogDo) Limit(limit int) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a abnormalPaymentLogDo) Offset(offset int) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a abnormalPaymentLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a abnormalPaymentLogDo) Unscoped() *abnormalPaymentLogDo {
	return a.withDO(a.DO.Unscoped())
}

func (a abnormalPaymentLogDo) Create(values ...*model.AbnormalPaymentLog) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

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

func (a abnormalPaymentLogDo) First() (*model.AbnormalPaymentLog, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.AbnormalPaymentLog), nil
	}
}

func (a abnormalPaymentLogDo) Take() (*model.AbnormalPaymentLog, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.AbnormalPaymentLog), nil
	}
}

func (a abnormalPaymentLogDo) Last() (*model.AbnormalPaymentLog, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.AbnormalPaymentLog), nil
	}
}

func (a abnormalPaymentLogDo) Find() ([]*model.AbnormalPaymentLog, error) {
	result, err := a.DO.Find()
	return result.([]*model.AbnormalPaymentLog), err
}

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

func (a abnormalPaymentLogDo) Attrs(attrs ...field.AssignExpr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a abnormalPaymentLogDo) Assign(attrs ...field.AssignExpr) *abnormalPaymentLogDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

func (a abnormalPaymentLogDo) FirstOrInit() (*model.AbnormalPaymentLog, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.AbnormalPaymentLog), nil
	}
}

func (a abnormalPaymentLogDo) FirstOrCreate() (*model.AbnormalPaymentLog, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.AbnormalPaymentLog), nil
	}
}

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

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

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

func (a abnormalPaymentLogDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a abnormalPaymentLogDo) Delete(models ...*model.AbnormalPaymentLog) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *abnormalPaymentLogDo) withDO(do gen.Dao) *abnormalPaymentLogDo {
	a.DO = *do.(*gen.DO)
	return a
}
