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

	_paymentNotifyEvents.paymentNotifyEventsDo.UseDB(db, opts...)
	_paymentNotifyEvents.paymentNotifyEventsDo.UseModel(&model.PaymentNotifyEvents{})

	tableName := _paymentNotifyEvents.paymentNotifyEventsDo.TableName()
	_paymentNotifyEvents.ALL = field.NewAsterisk(tableName)
	_paymentNotifyEvents.ID = field.NewInt64(tableName, "id")
	_paymentNotifyEvents.NotifyID = field.NewString(tableName, "notify_id")
	_paymentNotifyEvents.ResourceType = field.NewString(tableName, "resource_type")
	_paymentNotifyEvents.EventType = field.NewString(tableName, "event_type")
	_paymentNotifyEvents.Summary = field.NewString(tableName, "summary")
	_paymentNotifyEvents.Raw = field.NewString(tableName, "raw")
	_paymentNotifyEvents.Processed = field.NewBool(tableName, "processed")
	_paymentNotifyEvents.CreatedAt = field.NewTime(tableName, "created_at")

	_paymentNotifyEvents.fillFieldMap()

	return _paymentNotifyEvents
}

type paymentNotifyEvents struct {
	paymentNotifyEventsDo

	ALL          field.Asterisk
	ID           field.Int64
	NotifyID     field.String
	ResourceType field.String
	EventType    field.String
	Summary      field.String
	Raw          field.String
	Processed    field.Bool
	CreatedAt    field.Time

	fieldMap map[string]field.Expr
}

func (p paymentNotifyEvents) Table(newTableName string) *paymentNotifyEvents {
	p.paymentNotifyEventsDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *paymentNotifyEvents) updateTableName(table string) *paymentNotifyEvents {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.NotifyID = field.NewString(table, "notify_id")
	p.ResourceType = field.NewString(table, "resource_type")
	p.EventType = field.NewString(table, "event_type")
	p.Summary = field.NewString(table, "summary")
	p.Raw = field.NewString(table, "raw")
	p.Processed = field.NewBool(table, "processed")
	p.CreatedAt = field.NewTime(table, "created_at")

	p.fillFieldMap()

	return p
}

func (p *paymentNotifyEvents) 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 *paymentNotifyEvents) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 8)
	p.fieldMap["id"] = p.ID
	p.fieldMap["notify_id"] = p.NotifyID
	p.fieldMap["resource_type"] = p.ResourceType
	p.fieldMap["event_type"] = p.EventType
	p.fieldMap["summary"] = p.Summary
	p.fieldMap["raw"] = p.Raw
	p.fieldMap["processed"] = p.Processed
	p.fieldMap["created_at"] = p.CreatedAt
}

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

func (p paymentNotifyEvents) replaceDB(db *gorm.DB) paymentNotifyEvents {
	p.paymentNotifyEventsDo.ReplaceDB(db)
	return p
}

type paymentNotifyEventsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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