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

	_payOrderIos.payOrderIosDo.UseDB(db, opts...)
	_payOrderIos.payOrderIosDo.UseModel(&model.PayOrderIos{})

	tableName := _payOrderIos.payOrderIosDo.TableName()
	_payOrderIos.ALL = field.NewAsterisk(tableName)
	_payOrderIos.ID = field.NewInt64(tableName, "id")
	_payOrderIos.PlayerID = field.NewInt64(tableName, "playerId")
	_payOrderIos.GoodsID = field.NewInt32(tableName, "goodsID")
	_payOrderIos.OpenID = field.NewString(tableName, "openId")
	_payOrderIos.OutTradeNo = field.NewString(tableName, "outTradeNo")
	_payOrderIos.Total = field.NewInt32(tableName, "total")
	_payOrderIos.TradeState = field.NewString(tableName, "tradeState")
	_payOrderIos.TransactionID = field.NewString(tableName, "transactionId")
	_payOrderIos.PayerTotal = field.NewInt64(tableName, "payerTotal")
	_payOrderIos.SuccessTime = field.NewString(tableName, "successTime")
	_payOrderIos.PrepayID = field.NewString(tableName, "prepayId")
	_payOrderIos.State = field.NewInt32(tableName, "state")
	_payOrderIos.CreateTime = field.NewTime(tableName, "create_time")
	_payOrderIos.Platform = field.NewInt32(tableName, "platform")
	_payOrderIos.Phone = field.NewInt32(tableName, "phone")

	_payOrderIos.fillFieldMap()

	return _payOrderIos
}

type payOrderIos struct {
	payOrderIosDo

	ALL           field.Asterisk
	ID            field.Int64
	PlayerID      field.Int64
	GoodsID       field.Int32
	OpenID        field.String
	OutTradeNo    field.String
	Total         field.Int32
	TradeState    field.String
	TransactionID field.String
	PayerTotal    field.Int64
	SuccessTime   field.String
	PrepayID      field.String
	State         field.Int32
	CreateTime    field.Time
	Platform      field.Int32 // 1 微信 2抖音
	Phone         field.Int32

	fieldMap map[string]field.Expr
}

func (p payOrderIos) Table(newTableName string) *payOrderIos {
	p.payOrderIosDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *payOrderIos) updateTableName(table string) *payOrderIos {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.PlayerID = field.NewInt64(table, "playerId")
	p.GoodsID = field.NewInt32(table, "goodsID")
	p.OpenID = field.NewString(table, "openId")
	p.OutTradeNo = field.NewString(table, "outTradeNo")
	p.Total = field.NewInt32(table, "total")
	p.TradeState = field.NewString(table, "tradeState")
	p.TransactionID = field.NewString(table, "transactionId")
	p.PayerTotal = field.NewInt64(table, "payerTotal")
	p.SuccessTime = field.NewString(table, "successTime")
	p.PrepayID = field.NewString(table, "prepayId")
	p.State = field.NewInt32(table, "state")
	p.CreateTime = field.NewTime(table, "create_time")
	p.Platform = field.NewInt32(table, "platform")
	p.Phone = field.NewInt32(table, "phone")

	p.fillFieldMap()

	return p
}

func (p *payOrderIos) 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 *payOrderIos) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 15)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerId"] = p.PlayerID
	p.fieldMap["goodsID"] = p.GoodsID
	p.fieldMap["openId"] = p.OpenID
	p.fieldMap["outTradeNo"] = p.OutTradeNo
	p.fieldMap["total"] = p.Total
	p.fieldMap["tradeState"] = p.TradeState
	p.fieldMap["transactionId"] = p.TransactionID
	p.fieldMap["payerTotal"] = p.PayerTotal
	p.fieldMap["successTime"] = p.SuccessTime
	p.fieldMap["prepayId"] = p.PrepayID
	p.fieldMap["state"] = p.State
	p.fieldMap["create_time"] = p.CreateTime
	p.fieldMap["platform"] = p.Platform
	p.fieldMap["phone"] = p.Phone
}

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

func (p payOrderIos) replaceDB(db *gorm.DB) payOrderIos {
	p.payOrderIosDo.ReplaceDB(db)
	return p
}

type payOrderIosDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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