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

	_wxpayOrder.wxpayOrderDo.UseDB(db, opts...)
	_wxpayOrder.wxpayOrderDo.UseModel(&model.WxpayOrder{})

	tableName := _wxpayOrder.wxpayOrderDo.TableName()
	_wxpayOrder.ALL = field.NewAsterisk(tableName)
	_wxpayOrder.ID = field.NewInt64(tableName, "id")
	_wxpayOrder.Playerid = field.NewInt64(tableName, "playerid")
	_wxpayOrder.Platform = field.NewInt32(tableName, "platform")
	_wxpayOrder.GoodsID = field.NewInt32(tableName, "goodsId")
	_wxpayOrder.OrderID = field.NewString(tableName, "orderId")
	_wxpayOrder.State = field.NewInt32(tableName, "state")
	_wxpayOrder.CreateTime = field.NewTime(tableName, "create_time")
	_wxpayOrder.Method = field.NewInt32(tableName, "method")
	_wxpayOrder.Price = field.NewInt64(tableName, "price")

	_wxpayOrder.fillFieldMap()

	return _wxpayOrder
}

type wxpayOrder struct {
	wxpayOrderDo

	ALL        field.Asterisk
	ID         field.Int64
	Playerid   field.Int64
	Platform   field.Int32
	GoodsID    field.Int32
	OrderID    field.String
	State      field.Int32
	CreateTime field.Time
	Method     field.Int32
	Price      field.Int64

	fieldMap map[string]field.Expr
}

func (w wxpayOrder) Table(newTableName string) *wxpayOrder {
	w.wxpayOrderDo.UseTable(newTableName)
	return w.updateTableName(newTableName)
}

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

func (w *wxpayOrder) updateTableName(table string) *wxpayOrder {
	w.ALL = field.NewAsterisk(table)
	w.ID = field.NewInt64(table, "id")
	w.Playerid = field.NewInt64(table, "playerid")
	w.Platform = field.NewInt32(table, "platform")
	w.GoodsID = field.NewInt32(table, "goodsId")
	w.OrderID = field.NewString(table, "orderId")
	w.State = field.NewInt32(table, "state")
	w.CreateTime = field.NewTime(table, "create_time")
	w.Method = field.NewInt32(table, "method")
	w.Price = field.NewInt64(table, "price")

	w.fillFieldMap()

	return w
}

func (w *wxpayOrder) 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 *wxpayOrder) fillFieldMap() {
	w.fieldMap = make(map[string]field.Expr, 9)
	w.fieldMap["id"] = w.ID
	w.fieldMap["playerid"] = w.Playerid
	w.fieldMap["platform"] = w.Platform
	w.fieldMap["goodsId"] = w.GoodsID
	w.fieldMap["orderId"] = w.OrderID
	w.fieldMap["state"] = w.State
	w.fieldMap["create_time"] = w.CreateTime
	w.fieldMap["method"] = w.Method
	w.fieldMap["price"] = w.Price
}

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

func (w wxpayOrder) replaceDB(db *gorm.DB) wxpayOrder {
	w.wxpayOrderDo.ReplaceDB(db)
	return w
}

type wxpayOrderDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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