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

	_payOrderAndriod.payOrderAndriodDo.UseDB(db, opts...)
	_payOrderAndriod.payOrderAndriodDo.UseModel(&model.PayOrderAndriod{})

	tableName := _payOrderAndriod.payOrderAndriodDo.TableName()
	_payOrderAndriod.ALL = field.NewAsterisk(tableName)
	_payOrderAndriod.ID = field.NewInt64(tableName, "id")
	_payOrderAndriod.Playerid = field.NewInt64(tableName, "playerid")
	_payOrderAndriod.Balance = field.NewInt32(tableName, "balance")
	_payOrderAndriod.GenBalance = field.NewInt32(tableName, "genBalance")
	_payOrderAndriod.SaveSum = field.NewInt32(tableName, "saveSum")
	_payOrderAndriod.SaveAmt = field.NewInt32(tableName, "saveAmt")
	_payOrderAndriod.CostSum = field.NewInt32(tableName, "costSum")
	_payOrderAndriod.PresentSum = field.NewInt32(tableName, "presentSum")
	_payOrderAndriod.Operation = field.NewString(tableName, "operation")
	_payOrderAndriod.BillNo = field.NewString(tableName, "billNo")
	_payOrderAndriod.PayedBalance = field.NewInt32(tableName, "payedBalance")
	_payOrderAndriod.UsedGenAmt = field.NewInt32(tableName, "usedGenAmt")
	_payOrderAndriod.State = field.NewInt32(tableName, "state")
	_payOrderAndriod.GoodsID = field.NewInt64(tableName, "goodsId")
	_payOrderAndriod.Platform = field.NewInt64(tableName, "platform")
	_payOrderAndriod.PayMethod = field.NewInt32(tableName, "payMethod")
	_payOrderAndriod.CreateTime = field.NewTime(tableName, "create_time")

	_payOrderAndriod.fillFieldMap()

	return _payOrderAndriod
}

type payOrderAndriod struct {
	payOrderAndriodDo

	ALL          field.Asterisk
	ID           field.Int64
	Playerid     field.Int64
	Balance      field.Int32
	GenBalance   field.Int32
	SaveSum      field.Int32
	SaveAmt      field.Int32
	CostSum      field.Int32
	PresentSum   field.Int32
	Operation    field.String
	BillNo       field.String
	PayedBalance field.Int32
	UsedGenAmt   field.Int32
	State        field.Int32
	GoodsID      field.Int64
	Platform     field.Int64 // 1 微信 2抖音
	PayMethod    field.Int32 // 0：苹果游戏外微信支付 1:安卓游戏内支付 2：安卓游戏外微信支付 3:苹果游戏内支付
	CreateTime   field.Time

	fieldMap map[string]field.Expr
}

func (p payOrderAndriod) Table(newTableName string) *payOrderAndriod {
	p.payOrderAndriodDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

func (p payOrderAndriod) As(alias string) *payOrderAndriod {
	p.payOrderAndriodDo.DO = *(p.payOrderAndriodDo.As(alias).(*gen.DO))
	return p.updateTableName(alias)
}

func (p *payOrderAndriod) updateTableName(table string) *payOrderAndriod {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.Balance = field.NewInt32(table, "balance")
	p.GenBalance = field.NewInt32(table, "genBalance")
	p.SaveSum = field.NewInt32(table, "saveSum")
	p.SaveAmt = field.NewInt32(table, "saveAmt")
	p.CostSum = field.NewInt32(table, "costSum")
	p.PresentSum = field.NewInt32(table, "presentSum")
	p.Operation = field.NewString(table, "operation")
	p.BillNo = field.NewString(table, "billNo")
	p.PayedBalance = field.NewInt32(table, "payedBalance")
	p.UsedGenAmt = field.NewInt32(table, "usedGenAmt")
	p.State = field.NewInt32(table, "state")
	p.GoodsID = field.NewInt64(table, "goodsId")
	p.Platform = field.NewInt64(table, "platform")
	p.PayMethod = field.NewInt32(table, "payMethod")
	p.CreateTime = field.NewTime(table, "create_time")

	p.fillFieldMap()

	return p
}

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

func (p *payOrderAndriod) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 17)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["balance"] = p.Balance
	p.fieldMap["genBalance"] = p.GenBalance
	p.fieldMap["saveSum"] = p.SaveSum
	p.fieldMap["saveAmt"] = p.SaveAmt
	p.fieldMap["costSum"] = p.CostSum
	p.fieldMap["presentSum"] = p.PresentSum
	p.fieldMap["operation"] = p.Operation
	p.fieldMap["billNo"] = p.BillNo
	p.fieldMap["payedBalance"] = p.PayedBalance
	p.fieldMap["usedGenAmt"] = p.UsedGenAmt
	p.fieldMap["state"] = p.State
	p.fieldMap["goodsId"] = p.GoodsID
	p.fieldMap["platform"] = p.Platform
	p.fieldMap["payMethod"] = p.PayMethod
	p.fieldMap["create_time"] = p.CreateTime
}

func (p payOrderAndriod) clone(db *gorm.DB) payOrderAndriod {
	p.payOrderAndriodDo.ReplaceConnPool(db.Statement.ConnPool)
	return p
}

func (p payOrderAndriod) replaceDB(db *gorm.DB) payOrderAndriod {
	p.payOrderAndriodDo.ReplaceDB(db)
	return p
}

type payOrderAndriodDo struct{ gen.DO }

func (p payOrderAndriodDo) Debug() *payOrderAndriodDo {
	return p.withDO(p.DO.Debug())
}

func (p payOrderAndriodDo) WithContext(ctx context.Context) *payOrderAndriodDo {
	return p.withDO(p.DO.WithContext(ctx))
}

func (p payOrderAndriodDo) ReadDB() *payOrderAndriodDo {
	return p.Clauses(dbresolver.Read)
}

func (p payOrderAndriodDo) WriteDB() *payOrderAndriodDo {
	return p.Clauses(dbresolver.Write)
}

func (p payOrderAndriodDo) Session(config *gorm.Session) *payOrderAndriodDo {
	return p.withDO(p.DO.Session(config))
}

func (p payOrderAndriodDo) Clauses(conds ...clause.Expression) *payOrderAndriodDo {
	return p.withDO(p.DO.Clauses(conds...))
}

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

func (p payOrderAndriodDo) Not(conds ...gen.Condition) *payOrderAndriodDo {
	return p.withDO(p.DO.Not(conds...))
}

func (p payOrderAndriodDo) Or(conds ...gen.Condition) *payOrderAndriodDo {
	return p.withDO(p.DO.Or(conds...))
}

func (p payOrderAndriodDo) Select(conds ...field.Expr) *payOrderAndriodDo {
	return p.withDO(p.DO.Select(conds...))
}

func (p payOrderAndriodDo) Where(conds ...gen.Condition) *payOrderAndriodDo {
	return p.withDO(p.DO.Where(conds...))
}

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

func (p payOrderAndriodDo) Order(conds ...field.Expr) *payOrderAndriodDo {
	return p.withDO(p.DO.Order(conds...))
}

func (p payOrderAndriodDo) Distinct(cols ...field.Expr) *payOrderAndriodDo {
	return p.withDO(p.DO.Distinct(cols...))
}

func (p payOrderAndriodDo) Omit(cols ...field.Expr) *payOrderAndriodDo {
	return p.withDO(p.DO.Omit(cols...))
}

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

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

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

func (p payOrderAndriodDo) Group(cols ...field.Expr) *payOrderAndriodDo {
	return p.withDO(p.DO.Group(cols...))
}

func (p payOrderAndriodDo) Having(conds ...gen.Condition) *payOrderAndriodDo {
	return p.withDO(p.DO.Having(conds...))
}

func (p payOrderAndriodDo) Limit(limit int) *payOrderAndriodDo {
	return p.withDO(p.DO.Limit(limit))
}

func (p payOrderAndriodDo) Offset(offset int) *payOrderAndriodDo {
	return p.withDO(p.DO.Offset(offset))
}

func (p payOrderAndriodDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *payOrderAndriodDo {
	return p.withDO(p.DO.Scopes(funcs...))
}

func (p payOrderAndriodDo) Unscoped() *payOrderAndriodDo {
	return p.withDO(p.DO.Unscoped())
}

func (p payOrderAndriodDo) Create(values ...*model.PayOrderAndriod) error {
	if len(values) == 0 {
		return nil
	}
	return p.DO.Create(values)
}

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

func (p payOrderAndriodDo) First() (*model.PayOrderAndriod, error) {
	if result, err := p.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.PayOrderAndriod), nil
	}
}

func (p payOrderAndriodDo) Take() (*model.PayOrderAndriod, error) {
	if result, err := p.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.PayOrderAndriod), nil
	}
}

func (p payOrderAndriodDo) Last() (*model.PayOrderAndriod, error) {
	if result, err := p.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.PayOrderAndriod), nil
	}
}

func (p payOrderAndriodDo) Find() ([]*model.PayOrderAndriod, error) {
	result, err := p.DO.Find()
	return result.([]*model.PayOrderAndriod), err
}

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

func (p payOrderAndriodDo) Attrs(attrs ...field.AssignExpr) *payOrderAndriodDo {
	return p.withDO(p.DO.Attrs(attrs...))
}

func (p payOrderAndriodDo) Assign(attrs ...field.AssignExpr) *payOrderAndriodDo {
	return p.withDO(p.DO.Assign(attrs...))
}

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

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

func (p payOrderAndriodDo) FirstOrInit() (*model.PayOrderAndriod, error) {
	if result, err := p.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.PayOrderAndriod), nil
	}
}

func (p payOrderAndriodDo) FirstOrCreate() (*model.PayOrderAndriod, error) {
	if result, err := p.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.PayOrderAndriod), nil
	}
}

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

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

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

func (p payOrderAndriodDo) Scan(result interface{}) (err error) {
	return p.DO.Scan(result)
}

func (p payOrderAndriodDo) Delete(models ...*model.PayOrderAndriod) (result gen.ResultInfo, err error) {
	return p.DO.Delete(models)
}

func (p *payOrderAndriodDo) withDO(do gen.Dao) *payOrderAndriodDo {
	p.DO = *do.(*gen.DO)
	return p
}
