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

	_paymentTransactions.paymentTransactionsDo.UseDB(db, opts...)
	_paymentTransactions.paymentTransactionsDo.UseModel(&model.PaymentTransactions{})

	tableName := _paymentTransactions.paymentTransactionsDo.TableName()
	_paymentTransactions.ALL = field.NewAsterisk(tableName)
	_paymentTransactions.ID = field.NewInt64(tableName, "id")
	_paymentTransactions.OrderID = field.NewInt64(tableName, "order_id")
	_paymentTransactions.OrderNo = field.NewString(tableName, "order_no")
	_paymentTransactions.Channel = field.NewString(tableName, "channel")
	_paymentTransactions.TransactionID = field.NewString(tableName, "transaction_id")
	_paymentTransactions.AmountTotal = field.NewInt64(tableName, "amount_total")
	_paymentTransactions.SuccessTime = field.NewTime(tableName, "success_time")
	_paymentTransactions.Raw = field.NewString(tableName, "raw")
	_paymentTransactions.CreatedAt = field.NewTime(tableName, "created_at")

	_paymentTransactions.fillFieldMap()

	return _paymentTransactions
}

type paymentTransactions struct {
	paymentTransactionsDo

	ALL           field.Asterisk
	ID            field.Int64
	OrderID       field.Int64
	OrderNo       field.String
	Channel       field.String
	TransactionID field.String
	AmountTotal   field.Int64
	SuccessTime   field.Time
	Raw           field.String
	CreatedAt     field.Time

	fieldMap map[string]field.Expr
}

func (p paymentTransactions) Table(newTableName string) *paymentTransactions {
	p.paymentTransactionsDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *paymentTransactions) updateTableName(table string) *paymentTransactions {
	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.Channel = field.NewString(table, "channel")
	p.TransactionID = field.NewString(table, "transaction_id")
	p.AmountTotal = field.NewInt64(table, "amount_total")
	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 *paymentTransactions) 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 *paymentTransactions) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 9)
	p.fieldMap["id"] = p.ID
	p.fieldMap["order_id"] = p.OrderID
	p.fieldMap["order_no"] = p.OrderNo
	p.fieldMap["channel"] = p.Channel
	p.fieldMap["transaction_id"] = p.TransactionID
	p.fieldMap["amount_total"] = p.AmountTotal
	p.fieldMap["success_time"] = p.SuccessTime
	p.fieldMap["raw"] = p.Raw
	p.fieldMap["created_at"] = p.CreatedAt
}

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

func (p paymentTransactions) replaceDB(db *gorm.DB) paymentTransactions {
	p.paymentTransactionsDo.ReplaceDB(db)
	return p
}

type paymentTransactionsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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