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

	_wxpayPlayer.wxpayPlayerDo.UseDB(db, opts...)
	_wxpayPlayer.wxpayPlayerDo.UseModel(&model.WxpayPlayer{})

	tableName := _wxpayPlayer.wxpayPlayerDo.TableName()
	_wxpayPlayer.ALL = field.NewAsterisk(tableName)
	_wxpayPlayer.Playerid = field.NewInt64(tableName, "playerid")
	_wxpayPlayer.BuyStatis = field.NewString(tableName, "buyStatis")
	_wxpayPlayer.OrderBox = field.NewString(tableName, "orderBox")
	_wxpayPlayer.VipGoods = field.NewString(tableName, "vipGoods")
	_wxpayPlayer.DailyDiscount = field.NewString(tableName, "dailyDiscount")
	_wxpayPlayer.RoleGift = field.NewString(tableName, "roleGift")
	_wxpayPlayer.Invite = field.NewString(tableName, "invite")
	_wxpayPlayer.AccPay = field.NewString(tableName, "accPay")
	_wxpayPlayer.Balance = field.NewInt32(tableName, "balance")
	_wxpayPlayer.LuckDraw = field.NewString(tableName, "luckDraw")
	_wxpayPlayer.Growth = field.NewString(tableName, "growth")
	_wxpayPlayer.BoxKeyGift = field.NewString(tableName, "boxKeyGift")
	_wxpayPlayer.NewYearGift = field.NewString(tableName, "newYearGift")
	_wxpayPlayer.Fifteen = field.NewString(tableName, "fifteen")
	_wxpayPlayer.TombSweep = field.NewString(tableName, "tombSweep")
	_wxpayPlayer.Lady38 = field.NewString(tableName, "lady38")
	_wxpayPlayer.SpecialGift = field.NewString(tableName, "specialGift")
	_wxpayPlayer.RichMan = field.NewString(tableName, "richMan")
	_wxpayPlayer.DragonBoat = field.NewString(tableName, "dragonBoat")
	_wxpayPlayer.WeekendGift = field.NewString(tableName, "weekendGift")
	_wxpayPlayer.QiXiGift = field.NewString(tableName, "qiXiGift")
	_wxpayPlayer.MoonFestivalGift = field.NewString(tableName, "moonFestivalGift")

	_wxpayPlayer.fillFieldMap()

	return _wxpayPlayer
}

type wxpayPlayer struct {
	wxpayPlayerDo

	ALL              field.Asterisk
	Playerid         field.Int64
	BuyStatis        field.String
	OrderBox         field.String
	VipGoods         field.String
	DailyDiscount    field.String
	RoleGift         field.String
	Invite           field.String
	AccPay           field.String
	Balance          field.Int32
	LuckDraw         field.String
	Growth           field.String
	BoxKeyGift       field.String
	NewYearGift      field.String
	Fifteen          field.String
	TombSweep        field.String
	Lady38           field.String
	SpecialGift      field.String
	RichMan          field.String
	DragonBoat       field.String
	WeekendGift      field.String
	QiXiGift         field.String
	MoonFestivalGift field.String

	fieldMap map[string]field.Expr
}

func (w wxpayPlayer) Table(newTableName string) *wxpayPlayer {
	w.wxpayPlayerDo.UseTable(newTableName)
	return w.updateTableName(newTableName)
}

func (w wxpayPlayer) As(alias string) *wxpayPlayer {
	w.wxpayPlayerDo.DO = *(w.wxpayPlayerDo.As(alias).(*gen.DO))
	return w.updateTableName(alias)
}

func (w *wxpayPlayer) updateTableName(table string) *wxpayPlayer {
	w.ALL = field.NewAsterisk(table)
	w.Playerid = field.NewInt64(table, "playerid")
	w.BuyStatis = field.NewString(table, "buyStatis")
	w.OrderBox = field.NewString(table, "orderBox")
	w.VipGoods = field.NewString(table, "vipGoods")
	w.DailyDiscount = field.NewString(table, "dailyDiscount")
	w.RoleGift = field.NewString(table, "roleGift")
	w.Invite = field.NewString(table, "invite")
	w.AccPay = field.NewString(table, "accPay")
	w.Balance = field.NewInt32(table, "balance")
	w.LuckDraw = field.NewString(table, "luckDraw")
	w.Growth = field.NewString(table, "growth")
	w.BoxKeyGift = field.NewString(table, "boxKeyGift")
	w.NewYearGift = field.NewString(table, "newYearGift")
	w.Fifteen = field.NewString(table, "fifteen")
	w.TombSweep = field.NewString(table, "tombSweep")
	w.Lady38 = field.NewString(table, "lady38")
	w.SpecialGift = field.NewString(table, "specialGift")
	w.RichMan = field.NewString(table, "richMan")
	w.DragonBoat = field.NewString(table, "dragonBoat")
	w.WeekendGift = field.NewString(table, "weekendGift")
	w.QiXiGift = field.NewString(table, "qiXiGift")
	w.MoonFestivalGift = field.NewString(table, "moonFestivalGift")

	w.fillFieldMap()

	return w
}

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

func (w *wxpayPlayer) fillFieldMap() {
	w.fieldMap = make(map[string]field.Expr, 22)
	w.fieldMap["playerid"] = w.Playerid
	w.fieldMap["buyStatis"] = w.BuyStatis
	w.fieldMap["orderBox"] = w.OrderBox
	w.fieldMap["vipGoods"] = w.VipGoods
	w.fieldMap["dailyDiscount"] = w.DailyDiscount
	w.fieldMap["roleGift"] = w.RoleGift
	w.fieldMap["invite"] = w.Invite
	w.fieldMap["accPay"] = w.AccPay
	w.fieldMap["balance"] = w.Balance
	w.fieldMap["luckDraw"] = w.LuckDraw
	w.fieldMap["growth"] = w.Growth
	w.fieldMap["boxKeyGift"] = w.BoxKeyGift
	w.fieldMap["newYearGift"] = w.NewYearGift
	w.fieldMap["fifteen"] = w.Fifteen
	w.fieldMap["tombSweep"] = w.TombSweep
	w.fieldMap["lady38"] = w.Lady38
	w.fieldMap["specialGift"] = w.SpecialGift
	w.fieldMap["richMan"] = w.RichMan
	w.fieldMap["dragonBoat"] = w.DragonBoat
	w.fieldMap["weekendGift"] = w.WeekendGift
	w.fieldMap["qiXiGift"] = w.QiXiGift
	w.fieldMap["moonFestivalGift"] = w.MoonFestivalGift
}

func (w wxpayPlayer) clone(db *gorm.DB) wxpayPlayer {
	w.wxpayPlayerDo.ReplaceConnPool(db.Statement.ConnPool)
	return w
}

func (w wxpayPlayer) replaceDB(db *gorm.DB) wxpayPlayer {
	w.wxpayPlayerDo.ReplaceDB(db)
	return w
}

type wxpayPlayerDo struct{ gen.DO }

func (w wxpayPlayerDo) Debug() *wxpayPlayerDo {
	return w.withDO(w.DO.Debug())
}

func (w wxpayPlayerDo) WithContext(ctx context.Context) *wxpayPlayerDo {
	return w.withDO(w.DO.WithContext(ctx))
}

func (w wxpayPlayerDo) ReadDB() *wxpayPlayerDo {
	return w.Clauses(dbresolver.Read)
}

func (w wxpayPlayerDo) WriteDB() *wxpayPlayerDo {
	return w.Clauses(dbresolver.Write)
}

func (w wxpayPlayerDo) Session(config *gorm.Session) *wxpayPlayerDo {
	return w.withDO(w.DO.Session(config))
}

func (w wxpayPlayerDo) Clauses(conds ...clause.Expression) *wxpayPlayerDo {
	return w.withDO(w.DO.Clauses(conds...))
}

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

func (w wxpayPlayerDo) Not(conds ...gen.Condition) *wxpayPlayerDo {
	return w.withDO(w.DO.Not(conds...))
}

func (w wxpayPlayerDo) Or(conds ...gen.Condition) *wxpayPlayerDo {
	return w.withDO(w.DO.Or(conds...))
}

func (w wxpayPlayerDo) Select(conds ...field.Expr) *wxpayPlayerDo {
	return w.withDO(w.DO.Select(conds...))
}

func (w wxpayPlayerDo) Where(conds ...gen.Condition) *wxpayPlayerDo {
	return w.withDO(w.DO.Where(conds...))
}

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

func (w wxpayPlayerDo) Order(conds ...field.Expr) *wxpayPlayerDo {
	return w.withDO(w.DO.Order(conds...))
}

func (w wxpayPlayerDo) Distinct(cols ...field.Expr) *wxpayPlayerDo {
	return w.withDO(w.DO.Distinct(cols...))
}

func (w wxpayPlayerDo) Omit(cols ...field.Expr) *wxpayPlayerDo {
	return w.withDO(w.DO.Omit(cols...))
}

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

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

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

func (w wxpayPlayerDo) Group(cols ...field.Expr) *wxpayPlayerDo {
	return w.withDO(w.DO.Group(cols...))
}

func (w wxpayPlayerDo) Having(conds ...gen.Condition) *wxpayPlayerDo {
	return w.withDO(w.DO.Having(conds...))
}

func (w wxpayPlayerDo) Limit(limit int) *wxpayPlayerDo {
	return w.withDO(w.DO.Limit(limit))
}

func (w wxpayPlayerDo) Offset(offset int) *wxpayPlayerDo {
	return w.withDO(w.DO.Offset(offset))
}

func (w wxpayPlayerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *wxpayPlayerDo {
	return w.withDO(w.DO.Scopes(funcs...))
}

func (w wxpayPlayerDo) Unscoped() *wxpayPlayerDo {
	return w.withDO(w.DO.Unscoped())
}

func (w wxpayPlayerDo) Create(values ...*model.WxpayPlayer) error {
	if len(values) == 0 {
		return nil
	}
	return w.DO.Create(values)
}

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

func (w wxpayPlayerDo) First() (*model.WxpayPlayer, error) {
	if result, err := w.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.WxpayPlayer), nil
	}
}

func (w wxpayPlayerDo) Take() (*model.WxpayPlayer, error) {
	if result, err := w.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.WxpayPlayer), nil
	}
}

func (w wxpayPlayerDo) Last() (*model.WxpayPlayer, error) {
	if result, err := w.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.WxpayPlayer), nil
	}
}

func (w wxpayPlayerDo) Find() ([]*model.WxpayPlayer, error) {
	result, err := w.DO.Find()
	return result.([]*model.WxpayPlayer), err
}

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

func (w wxpayPlayerDo) Attrs(attrs ...field.AssignExpr) *wxpayPlayerDo {
	return w.withDO(w.DO.Attrs(attrs...))
}

func (w wxpayPlayerDo) Assign(attrs ...field.AssignExpr) *wxpayPlayerDo {
	return w.withDO(w.DO.Assign(attrs...))
}

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

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

func (w wxpayPlayerDo) FirstOrInit() (*model.WxpayPlayer, error) {
	if result, err := w.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.WxpayPlayer), nil
	}
}

func (w wxpayPlayerDo) FirstOrCreate() (*model.WxpayPlayer, error) {
	if result, err := w.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.WxpayPlayer), nil
	}
}

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

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

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

func (w wxpayPlayerDo) Scan(result interface{}) (err error) {
	return w.DO.Scan(result)
}

func (w wxpayPlayerDo) Delete(models ...*model.WxpayPlayer) (result gen.ResultInfo, err error) {
	return w.DO.Delete(models)
}

func (w *wxpayPlayerDo) withDO(do gen.Dao) *wxpayPlayerDo {
	w.DO = *do.(*gen.DO)
	return w
}
