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

	_clientDatum.clientDatumDo.UseDB(db, opts...)
	_clientDatum.clientDatumDo.UseModel(&model.ClientDatum{})

	tableName := _clientDatum.clientDatumDo.TableName()
	_clientDatum.ALL = field.NewAsterisk(tableName)
	_clientDatum.ID = field.NewInt64(tableName, "id")
	_clientDatum.Playerid = field.NewInt64(tableName, "playerid")
	_clientDatum.Videogift = field.NewString(tableName, "videogift")
	_clientDatum.CoinGifts = field.NewString(tableName, "coinGifts")
	_clientDatum.RoleRand = field.NewString(tableName, "roleRand")
	_clientDatum.Boxs = field.NewString(tableName, "boxs")

	_clientDatum.fillFieldMap()

	return _clientDatum
}

type clientDatum struct {
	clientDatumDo

	ALL       field.Asterisk
	ID        field.Int64
	Playerid  field.Int64
	Videogift field.String
	CoinGifts field.String
	RoleRand  field.String
	Boxs      field.String

	fieldMap map[string]field.Expr
}

func (c clientDatum) Table(newTableName string) *clientDatum {
	c.clientDatumDo.UseTable(newTableName)
	return c.updateTableName(newTableName)
}

func (c clientDatum) As(alias string) *clientDatum {
	c.clientDatumDo.DO = *(c.clientDatumDo.As(alias).(*gen.DO))
	return c.updateTableName(alias)
}

func (c *clientDatum) updateTableName(table string) *clientDatum {
	c.ALL = field.NewAsterisk(table)
	c.ID = field.NewInt64(table, "id")
	c.Playerid = field.NewInt64(table, "playerid")
	c.Videogift = field.NewString(table, "videogift")
	c.CoinGifts = field.NewString(table, "coinGifts")
	c.RoleRand = field.NewString(table, "roleRand")
	c.Boxs = field.NewString(table, "boxs")

	c.fillFieldMap()

	return c
}

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

func (c *clientDatum) fillFieldMap() {
	c.fieldMap = make(map[string]field.Expr, 6)
	c.fieldMap["id"] = c.ID
	c.fieldMap["playerid"] = c.Playerid
	c.fieldMap["videogift"] = c.Videogift
	c.fieldMap["coinGifts"] = c.CoinGifts
	c.fieldMap["roleRand"] = c.RoleRand
	c.fieldMap["boxs"] = c.Boxs
}

func (c clientDatum) clone(db *gorm.DB) clientDatum {
	c.clientDatumDo.ReplaceConnPool(db.Statement.ConnPool)
	return c
}

func (c clientDatum) replaceDB(db *gorm.DB) clientDatum {
	c.clientDatumDo.ReplaceDB(db)
	return c
}

type clientDatumDo struct{ gen.DO }

func (c clientDatumDo) Debug() *clientDatumDo {
	return c.withDO(c.DO.Debug())
}

func (c clientDatumDo) WithContext(ctx context.Context) *clientDatumDo {
	return c.withDO(c.DO.WithContext(ctx))
}

func (c clientDatumDo) ReadDB() *clientDatumDo {
	return c.Clauses(dbresolver.Read)
}

func (c clientDatumDo) WriteDB() *clientDatumDo {
	return c.Clauses(dbresolver.Write)
}

func (c clientDatumDo) Session(config *gorm.Session) *clientDatumDo {
	return c.withDO(c.DO.Session(config))
}

func (c clientDatumDo) Clauses(conds ...clause.Expression) *clientDatumDo {
	return c.withDO(c.DO.Clauses(conds...))
}

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

func (c clientDatumDo) Not(conds ...gen.Condition) *clientDatumDo {
	return c.withDO(c.DO.Not(conds...))
}

func (c clientDatumDo) Or(conds ...gen.Condition) *clientDatumDo {
	return c.withDO(c.DO.Or(conds...))
}

func (c clientDatumDo) Select(conds ...field.Expr) *clientDatumDo {
	return c.withDO(c.DO.Select(conds...))
}

func (c clientDatumDo) Where(conds ...gen.Condition) *clientDatumDo {
	return c.withDO(c.DO.Where(conds...))
}

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

func (c clientDatumDo) Order(conds ...field.Expr) *clientDatumDo {
	return c.withDO(c.DO.Order(conds...))
}

func (c clientDatumDo) Distinct(cols ...field.Expr) *clientDatumDo {
	return c.withDO(c.DO.Distinct(cols...))
}

func (c clientDatumDo) Omit(cols ...field.Expr) *clientDatumDo {
	return c.withDO(c.DO.Omit(cols...))
}

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

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

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

func (c clientDatumDo) Group(cols ...field.Expr) *clientDatumDo {
	return c.withDO(c.DO.Group(cols...))
}

func (c clientDatumDo) Having(conds ...gen.Condition) *clientDatumDo {
	return c.withDO(c.DO.Having(conds...))
}

func (c clientDatumDo) Limit(limit int) *clientDatumDo {
	return c.withDO(c.DO.Limit(limit))
}

func (c clientDatumDo) Offset(offset int) *clientDatumDo {
	return c.withDO(c.DO.Offset(offset))
}

func (c clientDatumDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *clientDatumDo {
	return c.withDO(c.DO.Scopes(funcs...))
}

func (c clientDatumDo) Unscoped() *clientDatumDo {
	return c.withDO(c.DO.Unscoped())
}

func (c clientDatumDo) Create(values ...*model.ClientDatum) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Create(values)
}

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

func (c clientDatumDo) First() (*model.ClientDatum, error) {
	if result, err := c.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ClientDatum), nil
	}
}

func (c clientDatumDo) Take() (*model.ClientDatum, error) {
	if result, err := c.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ClientDatum), nil
	}
}

func (c clientDatumDo) Last() (*model.ClientDatum, error) {
	if result, err := c.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ClientDatum), nil
	}
}

func (c clientDatumDo) Find() ([]*model.ClientDatum, error) {
	result, err := c.DO.Find()
	return result.([]*model.ClientDatum), err
}

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

func (c clientDatumDo) Attrs(attrs ...field.AssignExpr) *clientDatumDo {
	return c.withDO(c.DO.Attrs(attrs...))
}

func (c clientDatumDo) Assign(attrs ...field.AssignExpr) *clientDatumDo {
	return c.withDO(c.DO.Assign(attrs...))
}

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

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

func (c clientDatumDo) FirstOrInit() (*model.ClientDatum, error) {
	if result, err := c.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ClientDatum), nil
	}
}

func (c clientDatumDo) FirstOrCreate() (*model.ClientDatum, error) {
	if result, err := c.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ClientDatum), nil
	}
}

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

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

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

func (c clientDatumDo) Scan(result interface{}) (err error) {
	return c.DO.Scan(result)
}

func (c clientDatumDo) Delete(models ...*model.ClientDatum) (result gen.ResultInfo, err error) {
	return c.DO.Delete(models)
}

func (c *clientDatumDo) withDO(do gen.Dao) *clientDatumDo {
	c.DO = *do.(*gen.DO)
	return c
}
