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

	_processaward.processawardDo.UseDB(db, opts...)
	_processaward.processawardDo.UseModel(&model.Processaward{})

	tableName := _processaward.processawardDo.TableName()
	_processaward.ALL = field.NewAsterisk(tableName)
	_processaward.Playerid = field.NewInt64(tableName, "playerid")
	_processaward.Awards = field.NewString(tableName, "awards")

	_processaward.fillFieldMap()

	return _processaward
}

type processaward struct {
	processawardDo

	ALL      field.Asterisk
	Playerid field.Int64
	Awards   field.String

	fieldMap map[string]field.Expr
}

func (p processaward) Table(newTableName string) *processaward {
	p.processawardDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

func (p processaward) As(alias string) *processaward {
	p.processawardDo.DO = *(p.processawardDo.As(alias).(*gen.DO))
	return p.updateTableName(alias)
}

func (p *processaward) updateTableName(table string) *processaward {
	p.ALL = field.NewAsterisk(table)
	p.Playerid = field.NewInt64(table, "playerid")
	p.Awards = field.NewString(table, "awards")

	p.fillFieldMap()

	return p
}

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

func (p *processaward) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 2)
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["awards"] = p.Awards
}

func (p processaward) clone(db *gorm.DB) processaward {
	p.processawardDo.ReplaceConnPool(db.Statement.ConnPool)
	return p
}

func (p processaward) replaceDB(db *gorm.DB) processaward {
	p.processawardDo.ReplaceDB(db)
	return p
}

type processawardDo struct{ gen.DO }

func (p processawardDo) Debug() *processawardDo {
	return p.withDO(p.DO.Debug())
}

func (p processawardDo) WithContext(ctx context.Context) *processawardDo {
	return p.withDO(p.DO.WithContext(ctx))
}

func (p processawardDo) ReadDB() *processawardDo {
	return p.Clauses(dbresolver.Read)
}

func (p processawardDo) WriteDB() *processawardDo {
	return p.Clauses(dbresolver.Write)
}

func (p processawardDo) Session(config *gorm.Session) *processawardDo {
	return p.withDO(p.DO.Session(config))
}

func (p processawardDo) Clauses(conds ...clause.Expression) *processawardDo {
	return p.withDO(p.DO.Clauses(conds...))
}

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

func (p processawardDo) Not(conds ...gen.Condition) *processawardDo {
	return p.withDO(p.DO.Not(conds...))
}

func (p processawardDo) Or(conds ...gen.Condition) *processawardDo {
	return p.withDO(p.DO.Or(conds...))
}

func (p processawardDo) Select(conds ...field.Expr) *processawardDo {
	return p.withDO(p.DO.Select(conds...))
}

func (p processawardDo) Where(conds ...gen.Condition) *processawardDo {
	return p.withDO(p.DO.Where(conds...))
}

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

func (p processawardDo) Order(conds ...field.Expr) *processawardDo {
	return p.withDO(p.DO.Order(conds...))
}

func (p processawardDo) Distinct(cols ...field.Expr) *processawardDo {
	return p.withDO(p.DO.Distinct(cols...))
}

func (p processawardDo) Omit(cols ...field.Expr) *processawardDo {
	return p.withDO(p.DO.Omit(cols...))
}

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

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

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

func (p processawardDo) Group(cols ...field.Expr) *processawardDo {
	return p.withDO(p.DO.Group(cols...))
}

func (p processawardDo) Having(conds ...gen.Condition) *processawardDo {
	return p.withDO(p.DO.Having(conds...))
}

func (p processawardDo) Limit(limit int) *processawardDo {
	return p.withDO(p.DO.Limit(limit))
}

func (p processawardDo) Offset(offset int) *processawardDo {
	return p.withDO(p.DO.Offset(offset))
}

func (p processawardDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *processawardDo {
	return p.withDO(p.DO.Scopes(funcs...))
}

func (p processawardDo) Unscoped() *processawardDo {
	return p.withDO(p.DO.Unscoped())
}

func (p processawardDo) Create(values ...*model.Processaward) error {
	if len(values) == 0 {
		return nil
	}
	return p.DO.Create(values)
}

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

func (p processawardDo) First() (*model.Processaward, error) {
	if result, err := p.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Processaward), nil
	}
}

func (p processawardDo) Take() (*model.Processaward, error) {
	if result, err := p.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Processaward), nil
	}
}

func (p processawardDo) Last() (*model.Processaward, error) {
	if result, err := p.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Processaward), nil
	}
}

func (p processawardDo) Find() ([]*model.Processaward, error) {
	result, err := p.DO.Find()
	return result.([]*model.Processaward), err
}

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

func (p processawardDo) Attrs(attrs ...field.AssignExpr) *processawardDo {
	return p.withDO(p.DO.Attrs(attrs...))
}

func (p processawardDo) Assign(attrs ...field.AssignExpr) *processawardDo {
	return p.withDO(p.DO.Assign(attrs...))
}

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

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

func (p processawardDo) FirstOrInit() (*model.Processaward, error) {
	if result, err := p.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Processaward), nil
	}
}

func (p processawardDo) FirstOrCreate() (*model.Processaward, error) {
	if result, err := p.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Processaward), nil
	}
}

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

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

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

func (p processawardDo) Scan(result interface{}) (err error) {
	return p.DO.Scan(result)
}

func (p processawardDo) Delete(models ...*model.Processaward) (result gen.ResultInfo, err error) {
	return p.DO.Delete(models)
}

func (p *processawardDo) withDO(do gen.Dao) *processawardDo {
	p.DO = *do.(*gen.DO)
	return p
}
