// 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"

	"wechat-api/database/dao/wechat/model"
)

func newPayRecharge(db *gorm.DB, opts ...gen.DOOption) payRecharge {
	_payRecharge := payRecharge{}

	_payRecharge.payRechargeDo.UseDB(db, opts...)
	_payRecharge.payRechargeDo.UseModel(&model.PayRecharge{})

	tableName := _payRecharge.payRechargeDo.TableName()
	_payRecharge.ALL = field.NewAsterisk(tableName)
	_payRecharge.ID = field.NewInt64(tableName, "id")
	_payRecharge.CreatedAt = field.NewTime(tableName, "created_at")
	_payRecharge.UpdatedAt = field.NewTime(tableName, "updated_at")
	_payRecharge.Status = field.NewInt64(tableName, "status")
	_payRecharge.DeletedAt = field.NewField(tableName, "deleted_at")
	_payRecharge.UserID = field.NewString(tableName, "user_id")
	_payRecharge.Number = field.NewField(tableName, "number")
	_payRecharge.Money = field.NewField(tableName, "money")
	_payRecharge.OutTradeNo = field.NewString(tableName, "out_trade_no")
	_payRecharge.OrganizationID = field.NewInt64(tableName, "organization_id")

	_payRecharge.fillFieldMap()

	return _payRecharge
}

// payRecharge 充值表
type payRecharge struct {
	payRechargeDo

	ALL            field.Asterisk
	ID             field.Int64
	CreatedAt      field.Time   // Create Time | 创建日期
	UpdatedAt      field.Time   // Update Time | 修改日期
	Status         field.Int64  // 状态 1 正常 2 禁用
	DeletedAt      field.Field  // Delete Time | 删除日期
	UserID         field.String // 用户ID
	Number         field.Field  // 变化积分数
	Money          field.Field  // 充值钱数
	OutTradeNo     field.String // 外部订单号
	OrganizationID field.Int64  // 机构 ID

	fieldMap map[string]field.Expr
}

func (p payRecharge) Table(newTableName string) *payRecharge {
	p.payRechargeDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *payRecharge) updateTableName(table string) *payRecharge {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.CreatedAt = field.NewTime(table, "created_at")
	p.UpdatedAt = field.NewTime(table, "updated_at")
	p.Status = field.NewInt64(table, "status")
	p.DeletedAt = field.NewField(table, "deleted_at")
	p.UserID = field.NewString(table, "user_id")
	p.Number = field.NewField(table, "number")
	p.Money = field.NewField(table, "money")
	p.OutTradeNo = field.NewString(table, "out_trade_no")
	p.OrganizationID = field.NewInt64(table, "organization_id")

	p.fillFieldMap()

	return p
}

func (p *payRecharge) 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 *payRecharge) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 10)
	p.fieldMap["id"] = p.ID
	p.fieldMap["created_at"] = p.CreatedAt
	p.fieldMap["updated_at"] = p.UpdatedAt
	p.fieldMap["status"] = p.Status
	p.fieldMap["deleted_at"] = p.DeletedAt
	p.fieldMap["user_id"] = p.UserID
	p.fieldMap["number"] = p.Number
	p.fieldMap["money"] = p.Money
	p.fieldMap["out_trade_no"] = p.OutTradeNo
	p.fieldMap["organization_id"] = p.OrganizationID
}

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

func (p payRecharge) replaceDB(db *gorm.DB) payRecharge {
	p.payRechargeDo.ReplaceDB(db)
	return p
}

type payRechargeDo struct{ gen.DO }

type IPayRechargeDo interface {
	gen.SubQuery
	Debug() IPayRechargeDo
	WithContext(ctx context.Context) IPayRechargeDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() IPayRechargeDo
	WriteDB() IPayRechargeDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) IPayRechargeDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) IPayRechargeDo
	Not(conds ...gen.Condition) IPayRechargeDo
	Or(conds ...gen.Condition) IPayRechargeDo
	Select(conds ...field.Expr) IPayRechargeDo
	Where(conds ...gen.Condition) IPayRechargeDo
	Order(conds ...field.Expr) IPayRechargeDo
	Distinct(cols ...field.Expr) IPayRechargeDo
	Omit(cols ...field.Expr) IPayRechargeDo
	Join(table schema.Tabler, on ...field.Expr) IPayRechargeDo
	LeftJoin(table schema.Tabler, on ...field.Expr) IPayRechargeDo
	RightJoin(table schema.Tabler, on ...field.Expr) IPayRechargeDo
	Group(cols ...field.Expr) IPayRechargeDo
	Having(conds ...gen.Condition) IPayRechargeDo
	Limit(limit int) IPayRechargeDo
	Offset(offset int) IPayRechargeDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) IPayRechargeDo
	Unscoped() IPayRechargeDo
	Create(values ...*model.PayRecharge) error
	CreateInBatches(values []*model.PayRecharge, batchSize int) error
	Save(values ...*model.PayRecharge) error
	First() (*model.PayRecharge, error)
	Take() (*model.PayRecharge, error)
	Last() (*model.PayRecharge, error)
	Find() ([]*model.PayRecharge, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PayRecharge, err error)
	FindInBatches(result *[]*model.PayRecharge, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.PayRecharge) (info gen.ResultInfo, err error)
	Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	Updates(value interface{}) (info gen.ResultInfo, err error)
	UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
	UpdateFrom(q gen.SubQuery) gen.Dao
	Attrs(attrs ...field.AssignExpr) IPayRechargeDo
	Assign(attrs ...field.AssignExpr) IPayRechargeDo
	Joins(fields ...field.RelationField) IPayRechargeDo
	Preload(fields ...field.RelationField) IPayRechargeDo
	FirstOrInit() (*model.PayRecharge, error)
	FirstOrCreate() (*model.PayRecharge, error)
	FindByPage(offset int, limit int) (result []*model.PayRecharge, count int64, err error)
	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
	Scan(result interface{}) (err error)
	Returning(value interface{}, columns ...string) IPayRechargeDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (p payRechargeDo) Debug() IPayRechargeDo {
	return p.withDO(p.DO.Debug())
}

func (p payRechargeDo) WithContext(ctx context.Context) IPayRechargeDo {
	return p.withDO(p.DO.WithContext(ctx))
}

func (p payRechargeDo) ReadDB() IPayRechargeDo {
	return p.Clauses(dbresolver.Read)
}

func (p payRechargeDo) WriteDB() IPayRechargeDo {
	return p.Clauses(dbresolver.Write)
}

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

func (p payRechargeDo) Clauses(conds ...clause.Expression) IPayRechargeDo {
	return p.withDO(p.DO.Clauses(conds...))
}

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

func (p payRechargeDo) Not(conds ...gen.Condition) IPayRechargeDo {
	return p.withDO(p.DO.Not(conds...))
}

func (p payRechargeDo) Or(conds ...gen.Condition) IPayRechargeDo {
	return p.withDO(p.DO.Or(conds...))
}

func (p payRechargeDo) Select(conds ...field.Expr) IPayRechargeDo {
	return p.withDO(p.DO.Select(conds...))
}

func (p payRechargeDo) Where(conds ...gen.Condition) IPayRechargeDo {
	return p.withDO(p.DO.Where(conds...))
}

func (p payRechargeDo) Order(conds ...field.Expr) IPayRechargeDo {
	return p.withDO(p.DO.Order(conds...))
}

func (p payRechargeDo) Distinct(cols ...field.Expr) IPayRechargeDo {
	return p.withDO(p.DO.Distinct(cols...))
}

func (p payRechargeDo) Omit(cols ...field.Expr) IPayRechargeDo {
	return p.withDO(p.DO.Omit(cols...))
}

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

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

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

func (p payRechargeDo) Group(cols ...field.Expr) IPayRechargeDo {
	return p.withDO(p.DO.Group(cols...))
}

func (p payRechargeDo) Having(conds ...gen.Condition) IPayRechargeDo {
	return p.withDO(p.DO.Having(conds...))
}

func (p payRechargeDo) Limit(limit int) IPayRechargeDo {
	return p.withDO(p.DO.Limit(limit))
}

func (p payRechargeDo) Offset(offset int) IPayRechargeDo {
	return p.withDO(p.DO.Offset(offset))
}

func (p payRechargeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPayRechargeDo {
	return p.withDO(p.DO.Scopes(funcs...))
}

func (p payRechargeDo) Unscoped() IPayRechargeDo {
	return p.withDO(p.DO.Unscoped())
}

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

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

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

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

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

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

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

func (p payRechargeDo) Attrs(attrs ...field.AssignExpr) IPayRechargeDo {
	return p.withDO(p.DO.Attrs(attrs...))
}

func (p payRechargeDo) Assign(attrs ...field.AssignExpr) IPayRechargeDo {
	return p.withDO(p.DO.Assign(attrs...))
}

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

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

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

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

func (p payRechargeDo) FindByPage(offset int, limit int) (result []*model.PayRecharge, 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 payRechargeDo) 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 payRechargeDo) Scan(result interface{}) (err error) {
	return p.DO.Scan(result)
}

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

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