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

	_signin.signinDo.UseDB(db, opts...)
	_signin.signinDo.UseModel(&model.Signin{})

	tableName := _signin.signinDo.TableName()
	_signin.ALL = field.NewAsterisk(tableName)
	_signin.Playerid = field.NewInt64(tableName, "playerid")
	_signin.Sign = field.NewString(tableName, "sign")

	_signin.fillFieldMap()

	return _signin
}

type signin struct {
	signinDo

	ALL      field.Asterisk
	Playerid field.Int64
	Sign     field.String

	fieldMap map[string]field.Expr
}

func (s signin) Table(newTableName string) *signin {
	s.signinDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s signin) As(alias string) *signin {
	s.signinDo.DO = *(s.signinDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *signin) updateTableName(table string) *signin {
	s.ALL = field.NewAsterisk(table)
	s.Playerid = field.NewInt64(table, "playerid")
	s.Sign = field.NewString(table, "sign")

	s.fillFieldMap()

	return s
}

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

func (s *signin) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 2)
	s.fieldMap["playerid"] = s.Playerid
	s.fieldMap["sign"] = s.Sign
}

func (s signin) clone(db *gorm.DB) signin {
	s.signinDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s signin) replaceDB(db *gorm.DB) signin {
	s.signinDo.ReplaceDB(db)
	return s
}

type signinDo struct{ gen.DO }

func (s signinDo) Debug() *signinDo {
	return s.withDO(s.DO.Debug())
}

func (s signinDo) WithContext(ctx context.Context) *signinDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s signinDo) ReadDB() *signinDo {
	return s.Clauses(dbresolver.Read)
}

func (s signinDo) WriteDB() *signinDo {
	return s.Clauses(dbresolver.Write)
}

func (s signinDo) Session(config *gorm.Session) *signinDo {
	return s.withDO(s.DO.Session(config))
}

func (s signinDo) Clauses(conds ...clause.Expression) *signinDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s signinDo) Not(conds ...gen.Condition) *signinDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s signinDo) Or(conds ...gen.Condition) *signinDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s signinDo) Select(conds ...field.Expr) *signinDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s signinDo) Where(conds ...gen.Condition) *signinDo {
	return s.withDO(s.DO.Where(conds...))
}

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

func (s signinDo) Order(conds ...field.Expr) *signinDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s signinDo) Distinct(cols ...field.Expr) *signinDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s signinDo) Omit(cols ...field.Expr) *signinDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s signinDo) Group(cols ...field.Expr) *signinDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s signinDo) Having(conds ...gen.Condition) *signinDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s signinDo) Limit(limit int) *signinDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s signinDo) Offset(offset int) *signinDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s signinDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *signinDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s signinDo) Unscoped() *signinDo {
	return s.withDO(s.DO.Unscoped())
}

func (s signinDo) Create(values ...*model.Signin) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

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

func (s signinDo) First() (*model.Signin, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Signin), nil
	}
}

func (s signinDo) Take() (*model.Signin, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Signin), nil
	}
}

func (s signinDo) Last() (*model.Signin, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Signin), nil
	}
}

func (s signinDo) Find() ([]*model.Signin, error) {
	result, err := s.DO.Find()
	return result.([]*model.Signin), err
}

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

func (s signinDo) Attrs(attrs ...field.AssignExpr) *signinDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s signinDo) Assign(attrs ...field.AssignExpr) *signinDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s signinDo) FirstOrInit() (*model.Signin, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Signin), nil
	}
}

func (s signinDo) FirstOrCreate() (*model.Signin, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Signin), nil
	}
}

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

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

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

func (s signinDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s signinDo) Delete(models ...*model.Signin) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *signinDo) withDO(do gen.Dao) *signinDo {
	s.DO = *do.(*gen.DO)
	return s
}
