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

	_paymentBillDiff.paymentBillDiffDo.UseDB(db, opts...)
	_paymentBillDiff.paymentBillDiffDo.UseModel(&model.PaymentBillDiff{})

	tableName := _paymentBillDiff.paymentBillDiffDo.TableName()
	_paymentBillDiff.ALL = field.NewAsterisk(tableName)
	_paymentBillDiff.ID = field.NewInt64(tableName, "id")
	_paymentBillDiff.BillDate = field.NewTime(tableName, "bill_date")
	_paymentBillDiff.DiffType = field.NewString(tableName, "diff_type")
	_paymentBillDiff.LocalTxID = field.NewString(tableName, "local_tx_id")
	_paymentBillDiff.WechatTxID = field.NewString(tableName, "wechat_tx_id")
	_paymentBillDiff.Detail = field.NewString(tableName, "detail")
	_paymentBillDiff.CreatedAt = field.NewTime(tableName, "created_at")

	_paymentBillDiff.fillFieldMap()

	return _paymentBillDiff
}

type paymentBillDiff struct {
	paymentBillDiffDo

	ALL        field.Asterisk
	ID         field.Int64
	BillDate   field.Time
	DiffType   field.String
	LocalTxID  field.String
	WechatTxID field.String
	Detail     field.String
	CreatedAt  field.Time

	fieldMap map[string]field.Expr
}

func (p paymentBillDiff) Table(newTableName string) *paymentBillDiff {
	p.paymentBillDiffDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *paymentBillDiff) updateTableName(table string) *paymentBillDiff {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.BillDate = field.NewTime(table, "bill_date")
	p.DiffType = field.NewString(table, "diff_type")
	p.LocalTxID = field.NewString(table, "local_tx_id")
	p.WechatTxID = field.NewString(table, "wechat_tx_id")
	p.Detail = field.NewString(table, "detail")
	p.CreatedAt = field.NewTime(table, "created_at")

	p.fillFieldMap()

	return p
}

func (p *paymentBillDiff) 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 *paymentBillDiff) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 7)
	p.fieldMap["id"] = p.ID
	p.fieldMap["bill_date"] = p.BillDate
	p.fieldMap["diff_type"] = p.DiffType
	p.fieldMap["local_tx_id"] = p.LocalTxID
	p.fieldMap["wechat_tx_id"] = p.WechatTxID
	p.fieldMap["detail"] = p.Detail
	p.fieldMap["created_at"] = p.CreatedAt
}

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

func (p paymentBillDiff) replaceDB(db *gorm.DB) paymentBillDiff {
	p.paymentBillDiffDo.ReplaceDB(db)
	return p
}

type paymentBillDiffDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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