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

	_idiomLog.idiomLogDo.UseDB(db, opts...)
	_idiomLog.idiomLogDo.UseModel(&model.IdiomLog{})

	tableName := _idiomLog.idiomLogDo.TableName()
	_idiomLog.ALL = field.NewAsterisk(tableName)
	_idiomLog.ID = field.NewInt64(tableName, "id")
	_idiomLog.UserID = field.NewInt64(tableName, "user_id")
	_idiomLog.ServerID = field.NewInt32(tableName, "server_id")
	_idiomLog.EventID = field.NewInt32(tableName, "event_id")
	_idiomLog.Counter = field.NewInt32(tableName, "counter")
	_idiomLog.CostType = field.NewInt32(tableName, "cost_type")
	_idiomLog.Date = field.NewString(tableName, "date")
	_idiomLog.EventAt = field.NewInt32(tableName, "event_at")
	_idiomLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_idiomLog.fillFieldMap()

	return _idiomLog
}

type idiomLog struct {
	idiomLogDo

	ALL       field.Asterisk
	ID        field.Int64
	UserID    field.Int64  // 用户id
	ServerID  field.Int32  // 服务器ID
	EventID   field.Int32  // 事件ID
	Counter   field.Int32  // 获得墨水数量/得分/档位
	CostType  field.Int32  // 获取类型【1:看广告 2:钻石 】
	Date      field.String // 触发日期 2005-01-02
	EventAt   field.Int32  // 触发时间戳
	EventAtNs field.Int64  // 发生时间ns

	fieldMap map[string]field.Expr
}

func (i idiomLog) Table(newTableName string) *idiomLog {
	i.idiomLogDo.UseTable(newTableName)
	return i.updateTableName(newTableName)
}

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

func (i *idiomLog) updateTableName(table string) *idiomLog {
	i.ALL = field.NewAsterisk(table)
	i.ID = field.NewInt64(table, "id")
	i.UserID = field.NewInt64(table, "user_id")
	i.ServerID = field.NewInt32(table, "server_id")
	i.EventID = field.NewInt32(table, "event_id")
	i.Counter = field.NewInt32(table, "counter")
	i.CostType = field.NewInt32(table, "cost_type")
	i.Date = field.NewString(table, "date")
	i.EventAt = field.NewInt32(table, "event_at")
	i.EventAtNs = field.NewInt64(table, "event_at_ns")

	i.fillFieldMap()

	return i
}

func (i *idiomLog) 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 *idiomLog) fillFieldMap() {
	i.fieldMap = make(map[string]field.Expr, 9)
	i.fieldMap["id"] = i.ID
	i.fieldMap["user_id"] = i.UserID
	i.fieldMap["server_id"] = i.ServerID
	i.fieldMap["event_id"] = i.EventID
	i.fieldMap["counter"] = i.Counter
	i.fieldMap["cost_type"] = i.CostType
	i.fieldMap["date"] = i.Date
	i.fieldMap["event_at"] = i.EventAt
	i.fieldMap["event_at_ns"] = i.EventAtNs
}

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

func (i idiomLog) replaceDB(db *gorm.DB) idiomLog {
	i.idiomLogDo.ReplaceDB(db)
	return i
}

type idiomLogDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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