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

	_playerBanLog.playerBanLogDo.UseDB(db, opts...)
	_playerBanLog.playerBanLogDo.UseModel(&model.PlayerBanLog{})

	tableName := _playerBanLog.playerBanLogDo.TableName()
	_playerBanLog.ALL = field.NewAsterisk(tableName)
	_playerBanLog.ID = field.NewInt64(tableName, "id")
	_playerBanLog.ServerID = field.NewInt32(tableName, "server_id")
	_playerBanLog.Playerid = field.NewInt64(tableName, "playerid")
	_playerBanLog.AccID = field.NewInt64(tableName, "acc_id")
	_playerBanLog.Ban = field.NewInt32(tableName, "ban")
	_playerBanLog.Reason = field.NewString(tableName, "reason")
	_playerBanLog.Time = field.NewInt32(tableName, "time")

	_playerBanLog.fillFieldMap()

	return _playerBanLog
}

type playerBanLog struct {
	playerBanLogDo

	ALL      field.Asterisk
	ID       field.Int64
	ServerID field.Int32
	Playerid field.Int64 // 用户ID
	AccID    field.Int64
	Ban      field.Int32
	Reason   field.String // 拉黑原因
	Time     field.Int32

	fieldMap map[string]field.Expr
}

func (p playerBanLog) Table(newTableName string) *playerBanLog {
	p.playerBanLogDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *playerBanLog) updateTableName(table string) *playerBanLog {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.ServerID = field.NewInt32(table, "server_id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.AccID = field.NewInt64(table, "acc_id")
	p.Ban = field.NewInt32(table, "ban")
	p.Reason = field.NewString(table, "reason")
	p.Time = field.NewInt32(table, "time")

	p.fillFieldMap()

	return p
}

func (p *playerBanLog) 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 *playerBanLog) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 7)
	p.fieldMap["id"] = p.ID
	p.fieldMap["server_id"] = p.ServerID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["acc_id"] = p.AccID
	p.fieldMap["ban"] = p.Ban
	p.fieldMap["reason"] = p.Reason
	p.fieldMap["time"] = p.Time
}

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

func (p playerBanLog) replaceDB(db *gorm.DB) playerBanLog {
	p.playerBanLogDo.ReplaceDB(db)
	return p
}

type playerBanLogDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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