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

	_gameCharacterDataAnomaly.gameCharacterDataAnomalyDo.UseDB(db, opts...)
	_gameCharacterDataAnomaly.gameCharacterDataAnomalyDo.UseModel(&model.GameCharacterDataAnomaly{})

	tableName := _gameCharacterDataAnomaly.gameCharacterDataAnomalyDo.TableName()
	_gameCharacterDataAnomaly.ALL = field.NewAsterisk(tableName)
	_gameCharacterDataAnomaly.ID = field.NewInt64(tableName, "id")
	_gameCharacterDataAnomaly.ServerID = field.NewInt32(tableName, "server_id")
	_gameCharacterDataAnomaly.UserID = field.NewInt64(tableName, "user_id")
	_gameCharacterDataAnomaly.ChapterID = field.NewInt32(tableName, "chapter_id")
	_gameCharacterDataAnomaly.RoomID = field.NewInt32(tableName, "room_id")
	_gameCharacterDataAnomaly.Level = field.NewInt32(tableName, "level")
	_gameCharacterDataAnomaly.Key = field.NewString(tableName, "key")
	_gameCharacterDataAnomaly.CharacterData = field.NewString(tableName, "character_data")
	_gameCharacterDataAnomaly.CreatedAt = field.NewTime(tableName, "created_at")

	_gameCharacterDataAnomaly.fillFieldMap()

	return _gameCharacterDataAnomaly
}

type gameCharacterDataAnomaly struct {
	gameCharacterDataAnomalyDo

	ALL           field.Asterisk
	ID            field.Int64
	ServerID      field.Int32
	UserID        field.Int64
	ChapterID     field.Int32  // 关卡id
	RoomID        field.Int32  // 房间id
	Level         field.Int32  // 困难度
	Key           field.String // 解密用的eky
	CharacterData field.String
	CreatedAt     field.Time

	fieldMap map[string]field.Expr
}

func (g gameCharacterDataAnomaly) Table(newTableName string) *gameCharacterDataAnomaly {
	g.gameCharacterDataAnomalyDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

func (g gameCharacterDataAnomaly) As(alias string) *gameCharacterDataAnomaly {
	g.gameCharacterDataAnomalyDo.DO = *(g.gameCharacterDataAnomalyDo.As(alias).(*gen.DO))
	return g.updateTableName(alias)
}

func (g *gameCharacterDataAnomaly) updateTableName(table string) *gameCharacterDataAnomaly {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.ServerID = field.NewInt32(table, "server_id")
	g.UserID = field.NewInt64(table, "user_id")
	g.ChapterID = field.NewInt32(table, "chapter_id")
	g.RoomID = field.NewInt32(table, "room_id")
	g.Level = field.NewInt32(table, "level")
	g.Key = field.NewString(table, "key")
	g.CharacterData = field.NewString(table, "character_data")
	g.CreatedAt = field.NewTime(table, "created_at")

	g.fillFieldMap()

	return g
}

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

func (g *gameCharacterDataAnomaly) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 9)
	g.fieldMap["id"] = g.ID
	g.fieldMap["server_id"] = g.ServerID
	g.fieldMap["user_id"] = g.UserID
	g.fieldMap["chapter_id"] = g.ChapterID
	g.fieldMap["room_id"] = g.RoomID
	g.fieldMap["level"] = g.Level
	g.fieldMap["key"] = g.Key
	g.fieldMap["character_data"] = g.CharacterData
	g.fieldMap["created_at"] = g.CreatedAt
}

func (g gameCharacterDataAnomaly) clone(db *gorm.DB) gameCharacterDataAnomaly {
	g.gameCharacterDataAnomalyDo.ReplaceConnPool(db.Statement.ConnPool)
	return g
}

func (g gameCharacterDataAnomaly) replaceDB(db *gorm.DB) gameCharacterDataAnomaly {
	g.gameCharacterDataAnomalyDo.ReplaceDB(db)
	return g
}

type gameCharacterDataAnomalyDo struct{ gen.DO }

func (g gameCharacterDataAnomalyDo) Debug() *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Debug())
}

func (g gameCharacterDataAnomalyDo) WithContext(ctx context.Context) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.WithContext(ctx))
}

func (g gameCharacterDataAnomalyDo) ReadDB() *gameCharacterDataAnomalyDo {
	return g.Clauses(dbresolver.Read)
}

func (g gameCharacterDataAnomalyDo) WriteDB() *gameCharacterDataAnomalyDo {
	return g.Clauses(dbresolver.Write)
}

func (g gameCharacterDataAnomalyDo) Session(config *gorm.Session) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Session(config))
}

func (g gameCharacterDataAnomalyDo) Clauses(conds ...clause.Expression) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Clauses(conds...))
}

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

func (g gameCharacterDataAnomalyDo) Not(conds ...gen.Condition) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Not(conds...))
}

func (g gameCharacterDataAnomalyDo) Or(conds ...gen.Condition) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Or(conds...))
}

func (g gameCharacterDataAnomalyDo) Select(conds ...field.Expr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Select(conds...))
}

func (g gameCharacterDataAnomalyDo) Where(conds ...gen.Condition) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Where(conds...))
}

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

func (g gameCharacterDataAnomalyDo) Order(conds ...field.Expr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Order(conds...))
}

func (g gameCharacterDataAnomalyDo) Distinct(cols ...field.Expr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Distinct(cols...))
}

func (g gameCharacterDataAnomalyDo) Omit(cols ...field.Expr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Omit(cols...))
}

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

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

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

func (g gameCharacterDataAnomalyDo) Group(cols ...field.Expr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Group(cols...))
}

func (g gameCharacterDataAnomalyDo) Having(conds ...gen.Condition) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Having(conds...))
}

func (g gameCharacterDataAnomalyDo) Limit(limit int) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Limit(limit))
}

func (g gameCharacterDataAnomalyDo) Offset(offset int) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Offset(offset))
}

func (g gameCharacterDataAnomalyDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Scopes(funcs...))
}

func (g gameCharacterDataAnomalyDo) Unscoped() *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Unscoped())
}

func (g gameCharacterDataAnomalyDo) Create(values ...*model.GameCharacterDataAnomaly) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Create(values)
}

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

func (g gameCharacterDataAnomalyDo) First() (*model.GameCharacterDataAnomaly, error) {
	if result, err := g.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.GameCharacterDataAnomaly), nil
	}
}

func (g gameCharacterDataAnomalyDo) Take() (*model.GameCharacterDataAnomaly, error) {
	if result, err := g.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.GameCharacterDataAnomaly), nil
	}
}

func (g gameCharacterDataAnomalyDo) Last() (*model.GameCharacterDataAnomaly, error) {
	if result, err := g.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.GameCharacterDataAnomaly), nil
	}
}

func (g gameCharacterDataAnomalyDo) Find() ([]*model.GameCharacterDataAnomaly, error) {
	result, err := g.DO.Find()
	return result.([]*model.GameCharacterDataAnomaly), err
}

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

func (g gameCharacterDataAnomalyDo) Attrs(attrs ...field.AssignExpr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Attrs(attrs...))
}

func (g gameCharacterDataAnomalyDo) Assign(attrs ...field.AssignExpr) *gameCharacterDataAnomalyDo {
	return g.withDO(g.DO.Assign(attrs...))
}

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

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

func (g gameCharacterDataAnomalyDo) FirstOrInit() (*model.GameCharacterDataAnomaly, error) {
	if result, err := g.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.GameCharacterDataAnomaly), nil
	}
}

func (g gameCharacterDataAnomalyDo) FirstOrCreate() (*model.GameCharacterDataAnomaly, error) {
	if result, err := g.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.GameCharacterDataAnomaly), nil
	}
}

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

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

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

func (g gameCharacterDataAnomalyDo) Scan(result interface{}) (err error) {
	return g.DO.Scan(result)
}

func (g gameCharacterDataAnomalyDo) Delete(models ...*model.GameCharacterDataAnomaly) (result gen.ResultInfo, err error) {
	return g.DO.Delete(models)
}

func (g *gameCharacterDataAnomalyDo) withDO(do gen.Dao) *gameCharacterDataAnomalyDo {
	g.DO = *do.(*gen.DO)
	return g
}
