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

	_idiommatch.idiommatchDo.UseDB(db, opts...)
	_idiommatch.idiommatchDo.UseModel(&model.Idiommatch{})

	tableName := _idiommatch.idiommatchDo.TableName()
	_idiommatch.ALL = field.NewAsterisk(tableName)
	_idiommatch.Playerid = field.NewInt64(tableName, "playerid")
	_idiommatch.Ink = field.NewString(tableName, "ink")
	_idiommatch.Score = field.NewString(tableName, "score")
	_idiommatch.Scene = field.NewString(tableName, "scene")
	_idiommatch.IdiomRewards = field.NewString(tableName, "idiomRewards")
	_idiommatch.IdiomPreRewards = field.NewString(tableName, "idiomPreRewards")
	_idiommatch.StartTick = field.NewInt64(tableName, "startTick")

	_idiommatch.fillFieldMap()

	return _idiommatch
}

type idiommatch struct {
	idiommatchDo

	ALL             field.Asterisk
	Playerid        field.Int64
	Ink             field.String
	Score           field.String
	Scene           field.String
	IdiomRewards    field.String
	IdiomPreRewards field.String
	StartTick       field.Int64

	fieldMap map[string]field.Expr
}

func (i idiommatch) Table(newTableName string) *idiommatch {
	i.idiommatchDo.UseTable(newTableName)
	return i.updateTableName(newTableName)
}

func (i idiommatch) As(alias string) *idiommatch {
	i.idiommatchDo.DO = *(i.idiommatchDo.As(alias).(*gen.DO))
	return i.updateTableName(alias)
}

func (i *idiommatch) updateTableName(table string) *idiommatch {
	i.ALL = field.NewAsterisk(table)
	i.Playerid = field.NewInt64(table, "playerid")
	i.Ink = field.NewString(table, "ink")
	i.Score = field.NewString(table, "score")
	i.Scene = field.NewString(table, "scene")
	i.IdiomRewards = field.NewString(table, "idiomRewards")
	i.IdiomPreRewards = field.NewString(table, "idiomPreRewards")
	i.StartTick = field.NewInt64(table, "startTick")

	i.fillFieldMap()

	return i
}

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

func (i *idiommatch) fillFieldMap() {
	i.fieldMap = make(map[string]field.Expr, 7)
	i.fieldMap["playerid"] = i.Playerid
	i.fieldMap["ink"] = i.Ink
	i.fieldMap["score"] = i.Score
	i.fieldMap["scene"] = i.Scene
	i.fieldMap["idiomRewards"] = i.IdiomRewards
	i.fieldMap["idiomPreRewards"] = i.IdiomPreRewards
	i.fieldMap["startTick"] = i.StartTick
}

func (i idiommatch) clone(db *gorm.DB) idiommatch {
	i.idiommatchDo.ReplaceConnPool(db.Statement.ConnPool)
	return i
}

func (i idiommatch) replaceDB(db *gorm.DB) idiommatch {
	i.idiommatchDo.ReplaceDB(db)
	return i
}

type idiommatchDo struct{ gen.DO }

func (i idiommatchDo) Debug() *idiommatchDo {
	return i.withDO(i.DO.Debug())
}

func (i idiommatchDo) WithContext(ctx context.Context) *idiommatchDo {
	return i.withDO(i.DO.WithContext(ctx))
}

func (i idiommatchDo) ReadDB() *idiommatchDo {
	return i.Clauses(dbresolver.Read)
}

func (i idiommatchDo) WriteDB() *idiommatchDo {
	return i.Clauses(dbresolver.Write)
}

func (i idiommatchDo) Session(config *gorm.Session) *idiommatchDo {
	return i.withDO(i.DO.Session(config))
}

func (i idiommatchDo) Clauses(conds ...clause.Expression) *idiommatchDo {
	return i.withDO(i.DO.Clauses(conds...))
}

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

func (i idiommatchDo) Not(conds ...gen.Condition) *idiommatchDo {
	return i.withDO(i.DO.Not(conds...))
}

func (i idiommatchDo) Or(conds ...gen.Condition) *idiommatchDo {
	return i.withDO(i.DO.Or(conds...))
}

func (i idiommatchDo) Select(conds ...field.Expr) *idiommatchDo {
	return i.withDO(i.DO.Select(conds...))
}

func (i idiommatchDo) Where(conds ...gen.Condition) *idiommatchDo {
	return i.withDO(i.DO.Where(conds...))
}

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

func (i idiommatchDo) Order(conds ...field.Expr) *idiommatchDo {
	return i.withDO(i.DO.Order(conds...))
}

func (i idiommatchDo) Distinct(cols ...field.Expr) *idiommatchDo {
	return i.withDO(i.DO.Distinct(cols...))
}

func (i idiommatchDo) Omit(cols ...field.Expr) *idiommatchDo {
	return i.withDO(i.DO.Omit(cols...))
}

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

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

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

func (i idiommatchDo) Group(cols ...field.Expr) *idiommatchDo {
	return i.withDO(i.DO.Group(cols...))
}

func (i idiommatchDo) Having(conds ...gen.Condition) *idiommatchDo {
	return i.withDO(i.DO.Having(conds...))
}

func (i idiommatchDo) Limit(limit int) *idiommatchDo {
	return i.withDO(i.DO.Limit(limit))
}

func (i idiommatchDo) Offset(offset int) *idiommatchDo {
	return i.withDO(i.DO.Offset(offset))
}

func (i idiommatchDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *idiommatchDo {
	return i.withDO(i.DO.Scopes(funcs...))
}

func (i idiommatchDo) Unscoped() *idiommatchDo {
	return i.withDO(i.DO.Unscoped())
}

func (i idiommatchDo) Create(values ...*model.Idiommatch) error {
	if len(values) == 0 {
		return nil
	}
	return i.DO.Create(values)
}

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

func (i idiommatchDo) First() (*model.Idiommatch, error) {
	if result, err := i.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Idiommatch), nil
	}
}

func (i idiommatchDo) Take() (*model.Idiommatch, error) {
	if result, err := i.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Idiommatch), nil
	}
}

func (i idiommatchDo) Last() (*model.Idiommatch, error) {
	if result, err := i.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Idiommatch), nil
	}
}

func (i idiommatchDo) Find() ([]*model.Idiommatch, error) {
	result, err := i.DO.Find()
	return result.([]*model.Idiommatch), err
}

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

func (i idiommatchDo) Attrs(attrs ...field.AssignExpr) *idiommatchDo {
	return i.withDO(i.DO.Attrs(attrs...))
}

func (i idiommatchDo) Assign(attrs ...field.AssignExpr) *idiommatchDo {
	return i.withDO(i.DO.Assign(attrs...))
}

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

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

func (i idiommatchDo) FirstOrInit() (*model.Idiommatch, error) {
	if result, err := i.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Idiommatch), nil
	}
}

func (i idiommatchDo) FirstOrCreate() (*model.Idiommatch, error) {
	if result, err := i.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Idiommatch), nil
	}
}

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

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

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

func (i idiommatchDo) Scan(result interface{}) (err error) {
	return i.DO.Scan(result)
}

func (i idiommatchDo) Delete(models ...*model.Idiommatch) (result gen.ResultInfo, err error) {
	return i.DO.Delete(models)
}

func (i *idiommatchDo) withDO(do gen.Dao) *idiommatchDo {
	i.DO = *do.(*gen.DO)
	return i
}
