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

	_adminBanUserLog.adminBanUserLogDo.UseDB(db, opts...)
	_adminBanUserLog.adminBanUserLogDo.UseModel(&model.AdminBanUserLog{})

	tableName := _adminBanUserLog.adminBanUserLogDo.TableName()
	_adminBanUserLog.ALL = field.NewAsterisk(tableName)
	_adminBanUserLog.ID = field.NewInt64(tableName, "id")
	_adminBanUserLog.AdminID = field.NewInt32(tableName, "admin_id")
	_adminBanUserLog.IP = field.NewString(tableName, "ip")
	_adminBanUserLog.PlayerID = field.NewInt64(tableName, "player_id")
	_adminBanUserLog.Type = field.NewInt32(tableName, "type")
	_adminBanUserLog.Reason = field.NewString(tableName, "reason")
	_adminBanUserLog.CreateAt = field.NewInt32(tableName, "create_at")
	_adminBanUserLog.UpdateAt = field.NewInt32(tableName, "update_at")

	_adminBanUserLog.fillFieldMap()

	return _adminBanUserLog
}

type adminBanUserLog struct {
	adminBanUserLogDo adminBanUserLogDo

	ALL      field.Asterisk
	ID       field.Int64  // 自增id
	AdminID  field.Int32  // 管理员id
	IP       field.String // 操作人员ip
	PlayerID field.Int64  // 玩家id
	Type     field.Int32  // 禁用类型 1 全服，2当前服，3 支付，4 聊天
	Reason   field.String // 原因
	CreateAt field.Int32  // 创建时间
	UpdateAt field.Int32  // 修改时间

	fieldMap map[string]field.Expr
}

func (a adminBanUserLog) Table(newTableName string) *adminBanUserLog {
	a.adminBanUserLogDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a adminBanUserLog) As(alias string) *adminBanUserLog {
	a.adminBanUserLogDo.DO = *(a.adminBanUserLogDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *adminBanUserLog) updateTableName(table string) *adminBanUserLog {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.AdminID = field.NewInt32(table, "admin_id")
	a.IP = field.NewString(table, "ip")
	a.PlayerID = field.NewInt64(table, "player_id")
	a.Type = field.NewInt32(table, "type")
	a.Reason = field.NewString(table, "reason")
	a.CreateAt = field.NewInt32(table, "create_at")
	a.UpdateAt = field.NewInt32(table, "update_at")

	a.fillFieldMap()

	return a
}

func (a *adminBanUserLog) WithContext(ctx context.Context) *adminBanUserLogDo {
	return a.adminBanUserLogDo.WithContext(ctx)
}

func (a adminBanUserLog) TableName() string { return a.adminBanUserLogDo.TableName() }

func (a adminBanUserLog) Alias() string { return a.adminBanUserLogDo.Alias() }

func (a adminBanUserLog) Columns(cols ...field.Expr) gen.Columns {
	return a.adminBanUserLogDo.Columns(cols...)
}

func (a *adminBanUserLog) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := a.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (a *adminBanUserLog) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 8)
	a.fieldMap["id"] = a.ID
	a.fieldMap["admin_id"] = a.AdminID
	a.fieldMap["ip"] = a.IP
	a.fieldMap["player_id"] = a.PlayerID
	a.fieldMap["type"] = a.Type
	a.fieldMap["reason"] = a.Reason
	a.fieldMap["create_at"] = a.CreateAt
	a.fieldMap["update_at"] = a.UpdateAt
}

func (a adminBanUserLog) clone(db *gorm.DB) adminBanUserLog {
	a.adminBanUserLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a adminBanUserLog) replaceDB(db *gorm.DB) adminBanUserLog {
	a.adminBanUserLogDo.ReplaceDB(db)
	return a
}

type adminBanUserLogDo struct{ gen.DO }

func (a adminBanUserLogDo) Debug() *adminBanUserLogDo {
	return a.withDO(a.DO.Debug())
}

func (a adminBanUserLogDo) WithContext(ctx context.Context) *adminBanUserLogDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a adminBanUserLogDo) ReadDB() *adminBanUserLogDo {
	return a.Clauses(dbresolver.Read)
}

func (a adminBanUserLogDo) WriteDB() *adminBanUserLogDo {
	return a.Clauses(dbresolver.Write)
}

func (a adminBanUserLogDo) Session(config *gorm.Session) *adminBanUserLogDo {
	return a.withDO(a.DO.Session(config))
}

func (a adminBanUserLogDo) Clauses(conds ...clause.Expression) *adminBanUserLogDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a adminBanUserLogDo) Not(conds ...gen.Condition) *adminBanUserLogDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a adminBanUserLogDo) Or(conds ...gen.Condition) *adminBanUserLogDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a adminBanUserLogDo) Select(conds ...field.Expr) *adminBanUserLogDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a adminBanUserLogDo) Where(conds ...gen.Condition) *adminBanUserLogDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a adminBanUserLogDo) Order(conds ...field.Expr) *adminBanUserLogDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a adminBanUserLogDo) Distinct(cols ...field.Expr) *adminBanUserLogDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a adminBanUserLogDo) Omit(cols ...field.Expr) *adminBanUserLogDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a adminBanUserLogDo) Group(cols ...field.Expr) *adminBanUserLogDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a adminBanUserLogDo) Having(conds ...gen.Condition) *adminBanUserLogDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a adminBanUserLogDo) Limit(limit int) *adminBanUserLogDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a adminBanUserLogDo) Offset(offset int) *adminBanUserLogDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a adminBanUserLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *adminBanUserLogDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a adminBanUserLogDo) Unscoped() *adminBanUserLogDo {
	return a.withDO(a.DO.Unscoped())
}

func (a adminBanUserLogDo) Create(values ...*model.AdminBanUserLog) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

func (a adminBanUserLogDo) CreateInBatches(values []*model.AdminBanUserLog, batchSize int) error {
	return a.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 (a adminBanUserLogDo) Save(values ...*model.AdminBanUserLog) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Save(values)
}

func (a adminBanUserLogDo) First() (*model.AdminBanUserLog, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminBanUserLog), nil
	}
}

func (a adminBanUserLogDo) Take() (*model.AdminBanUserLog, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminBanUserLog), nil
	}
}

func (a adminBanUserLogDo) Last() (*model.AdminBanUserLog, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminBanUserLog), nil
	}
}

func (a adminBanUserLogDo) Find() ([]*model.AdminBanUserLog, error) {
	result, err := a.DO.Find()
	return result.([]*model.AdminBanUserLog), err
}

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

func (a adminBanUserLogDo) Attrs(attrs ...field.AssignExpr) *adminBanUserLogDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a adminBanUserLogDo) Assign(attrs ...field.AssignExpr) *adminBanUserLogDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

func (a adminBanUserLogDo) FirstOrInit() (*model.AdminBanUserLog, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminBanUserLog), nil
	}
}

func (a adminBanUserLogDo) FirstOrCreate() (*model.AdminBanUserLog, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminBanUserLog), nil
	}
}

func (a adminBanUserLogDo) FindByPage(offset int, limit int) (result []*model.AdminBanUserLog, count int64, err error) {
	result, err = a.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 = a.Offset(-1).Limit(-1).Count()
	return
}

func (a adminBanUserLogDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = a.Count()
	if err != nil {
		return
	}

	err = a.Offset(offset).Limit(limit).Scan(result)
	return
}

func (a adminBanUserLogDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a adminBanUserLogDo) Delete(models ...*model.AdminBanUserLog) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *adminBanUserLogDo) withDO(do gen.Dao) *adminBanUserLogDo {
	a.DO = *do.(*gen.DO)
	return a
}
