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

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"bindbox-game/internal/repository/mysql/model"
)

func newPaymentRefunds(db *gorm.DB, opts ...gen.DOOption) paymentRefunds {
	_paymentRefunds := paymentRefunds{}

	_paymentRefunds.paymentRefundsDo.UseDB(db, opts...)
	_paymentRefunds.paymentRefundsDo.UseModel(&model.PaymentRefunds{})

	tableName := _paymentRefunds.paymentRefundsDo.TableName()
	_paymentRefunds.ALL = field.NewAsterisk(tableName)
	_paymentRefunds.ID = field.NewInt64(tableName, "id")
	_paymentRefunds.OrderID = field.NewInt64(tableName, "order_id")
	_paymentRefunds.OrderNo = field.NewString(tableName, "order_no")
	_paymentRefunds.RefundNo = field.NewString(tableName, "refund_no")
	_paymentRefunds.Channel = field.NewString(tableName, "channel")
	_paymentRefunds.Status = field.NewString(tableName, "status")
	_paymentRefunds.AmountRefund = field.NewInt64(tableName, "amount_refund")
	_paymentRefunds.Reason = field.NewString(tableName, "reason")
	_paymentRefunds.SuccessTime = field.NewTime(tableName, "success_time")
	_paymentRefunds.Raw = field.NewString(tableName, "raw")
	_paymentRefunds.CreatedAt = field.NewTime(tableName, "created_at")

	_paymentRefunds.fillFieldMap()

	return _paymentRefunds
}

type paymentRefunds struct {
	paymentRefundsDo

	ALL          field.Asterisk
	ID           field.Int64
	OrderID      field.Int64
	OrderNo      field.String
	RefundNo     field.String
	Channel      field.String
	Status       field.String
	AmountRefund field.Int64
	Reason       field.String
	SuccessTime  field.Time
	Raw          field.String
	CreatedAt    field.Time

	fieldMap map[string]field.Expr
}

func (p paymentRefunds) Table(newTableName string) *paymentRefunds {
	p.paymentRefundsDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *paymentRefunds) updateTableName(table string) *paymentRefunds {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.OrderID = field.NewInt64(table, "order_id")
	p.OrderNo = field.NewString(table, "order_no")
	p.RefundNo = field.NewString(table, "refund_no")
	p.Channel = field.NewString(table, "channel")
	p.Status = field.NewString(table, "status")
	p.AmountRefund = field.NewInt64(table, "amount_refund")
	p.Reason = field.NewString(table, "reason")
	p.SuccessTime = field.NewTime(table, "success_time")
	p.Raw = field.NewString(table, "raw")
	p.CreatedAt = field.NewTime(table, "created_at")

	p.fillFieldMap()

	return p
}

func (p *paymentRefunds) 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 *paymentRefunds) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 11)
	p.fieldMap["id"] = p.ID
	p.fieldMap["order_id"] = p.OrderID
	p.fieldMap["order_no"] = p.OrderNo
	p.fieldMap["refund_no"] = p.RefundNo
	p.fieldMap["channel"] = p.Channel
	p.fieldMap["status"] = p.Status
	p.fieldMap["amount_refund"] = p.AmountRefund
	p.fieldMap["reason"] = p.Reason
	p.fieldMap["success_time"] = p.SuccessTime
	p.fieldMap["raw"] = p.Raw
	p.fieldMap["created_at"] = p.CreatedAt
}

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

func (p paymentRefunds) replaceDB(db *gorm.DB) paymentRefunds {
	p.paymentRefundsDo.ReplaceDB(db)
	return p
}

type paymentRefundsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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