// 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 dal

import (
	"app/internal/models"
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"
)

func newTeamType(db *gorm.DB, opts ...gen.DOOption) teamType {
	_teamType := teamType{}

	_teamType.teamTypeDo.UseDB(db, opts...)
	_teamType.teamTypeDo.UseModel(&models.TeamType{})

	tableName := _teamType.teamTypeDo.TableName()
	_teamType.ALL = field.NewAsterisk(tableName)
	_teamType.Id = field.NewUint(tableName, "id")
	_teamType.Name = field.NewString(tableName, "name")

	_teamType.fillFieldMap()

	return _teamType
}

type teamType struct {
	teamTypeDo

	ALL  field.Asterisk
	Id   field.Uint
	Name field.String

	fieldMap map[string]field.Expr
}

func (t teamType) Table(newTableName string) *teamType {
	t.teamTypeDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

func (t teamType) As(alias string) *teamType {
	t.teamTypeDo.DO = *(t.teamTypeDo.As(alias).(*gen.DO))
	return t.updateTableName(alias)
}

func (t *teamType) updateTableName(table string) *teamType {
	t.ALL = field.NewAsterisk(table)
	t.Id = field.NewUint(table, "id")
	t.Name = field.NewString(table, "name")

	t.fillFieldMap()

	return t
}

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

func (t *teamType) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 2)
	t.fieldMap["id"] = t.Id
	t.fieldMap["name"] = t.Name
}

func (t teamType) clone(db *gorm.DB) teamType {
	t.teamTypeDo.ReplaceConnPool(db.Statement.ConnPool)
	return t
}

func (t teamType) replaceDB(db *gorm.DB) teamType {
	t.teamTypeDo.ReplaceDB(db)
	return t
}

type teamTypeDo struct{ gen.DO }

type ITeamTypeDo interface {
	gen.SubQuery
	Debug() ITeamTypeDo
	WithContext(ctx context.Context) ITeamTypeDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() ITeamTypeDo
	WriteDB() ITeamTypeDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) ITeamTypeDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) ITeamTypeDo
	Not(conds ...gen.Condition) ITeamTypeDo
	Or(conds ...gen.Condition) ITeamTypeDo
	Select(conds ...field.Expr) ITeamTypeDo
	Where(conds ...gen.Condition) ITeamTypeDo
	Order(conds ...field.Expr) ITeamTypeDo
	Distinct(cols ...field.Expr) ITeamTypeDo
	Omit(cols ...field.Expr) ITeamTypeDo
	Join(table schema.Tabler, on ...field.Expr) ITeamTypeDo
	LeftJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo
	RightJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo
	Group(cols ...field.Expr) ITeamTypeDo
	Having(conds ...gen.Condition) ITeamTypeDo
	Limit(limit int) ITeamTypeDo
	Offset(offset int) ITeamTypeDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) ITeamTypeDo
	Unscoped() ITeamTypeDo
	Create(values ...*models.TeamType) error
	CreateInBatches(values []*models.TeamType, batchSize int) error
	Save(values ...*models.TeamType) error
	First() (*models.TeamType, error)
	Take() (*models.TeamType, error)
	Last() (*models.TeamType, error)
	Find() ([]*models.TeamType, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.TeamType, err error)
	FindInBatches(result *[]*models.TeamType, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*models.TeamType) (info gen.ResultInfo, err error)
	Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	Updates(value interface{}) (info gen.ResultInfo, err error)
	UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
	UpdateFrom(q gen.SubQuery) gen.Dao
	Attrs(attrs ...field.AssignExpr) ITeamTypeDo
	Assign(attrs ...field.AssignExpr) ITeamTypeDo
	Joins(fields ...field.RelationField) ITeamTypeDo
	Preload(fields ...field.RelationField) ITeamTypeDo
	FirstOrInit() (*models.TeamType, error)
	FirstOrCreate() (*models.TeamType, error)
	FindByPage(offset int, limit int) (result []*models.TeamType, count int64, err error)
	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
	Scan(result interface{}) (err error)
	Returning(value interface{}, columns ...string) ITeamTypeDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (t teamTypeDo) Debug() ITeamTypeDo {
	return t.withDO(t.DO.Debug())
}

func (t teamTypeDo) WithContext(ctx context.Context) ITeamTypeDo {
	return t.withDO(t.DO.WithContext(ctx))
}

func (t teamTypeDo) ReadDB() ITeamTypeDo {
	return t.Clauses(dbresolver.Read)
}

func (t teamTypeDo) WriteDB() ITeamTypeDo {
	return t.Clauses(dbresolver.Write)
}

func (t teamTypeDo) Session(config *gorm.Session) ITeamTypeDo {
	return t.withDO(t.DO.Session(config))
}

func (t teamTypeDo) Clauses(conds ...clause.Expression) ITeamTypeDo {
	return t.withDO(t.DO.Clauses(conds...))
}

func (t teamTypeDo) Returning(value interface{}, columns ...string) ITeamTypeDo {
	return t.withDO(t.DO.Returning(value, columns...))
}

func (t teamTypeDo) Not(conds ...gen.Condition) ITeamTypeDo {
	return t.withDO(t.DO.Not(conds...))
}

func (t teamTypeDo) Or(conds ...gen.Condition) ITeamTypeDo {
	return t.withDO(t.DO.Or(conds...))
}

func (t teamTypeDo) Select(conds ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.Select(conds...))
}

func (t teamTypeDo) Where(conds ...gen.Condition) ITeamTypeDo {
	return t.withDO(t.DO.Where(conds...))
}

func (t teamTypeDo) Order(conds ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.Order(conds...))
}

func (t teamTypeDo) Distinct(cols ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.Distinct(cols...))
}

func (t teamTypeDo) Omit(cols ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.Omit(cols...))
}

func (t teamTypeDo) Join(table schema.Tabler, on ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.Join(table, on...))
}

func (t teamTypeDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.LeftJoin(table, on...))
}

func (t teamTypeDo) RightJoin(table schema.Tabler, on ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.RightJoin(table, on...))
}

func (t teamTypeDo) Group(cols ...field.Expr) ITeamTypeDo {
	return t.withDO(t.DO.Group(cols...))
}

func (t teamTypeDo) Having(conds ...gen.Condition) ITeamTypeDo {
	return t.withDO(t.DO.Having(conds...))
}

func (t teamTypeDo) Limit(limit int) ITeamTypeDo {
	return t.withDO(t.DO.Limit(limit))
}

func (t teamTypeDo) Offset(offset int) ITeamTypeDo {
	return t.withDO(t.DO.Offset(offset))
}

func (t teamTypeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITeamTypeDo {
	return t.withDO(t.DO.Scopes(funcs...))
}

func (t teamTypeDo) Unscoped() ITeamTypeDo {
	return t.withDO(t.DO.Unscoped())
}

func (t teamTypeDo) Create(values ...*models.TeamType) error {
	if len(values) == 0 {
		return nil
	}
	return t.DO.Create(values)
}

func (t teamTypeDo) CreateInBatches(values []*models.TeamType, batchSize int) error {
	return t.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 (t teamTypeDo) Save(values ...*models.TeamType) error {
	if len(values) == 0 {
		return nil
	}
	return t.DO.Save(values)
}

func (t teamTypeDo) First() (*models.TeamType, error) {
	if result, err := t.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*models.TeamType), nil
	}
}

func (t teamTypeDo) Take() (*models.TeamType, error) {
	if result, err := t.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*models.TeamType), nil
	}
}

func (t teamTypeDo) Last() (*models.TeamType, error) {
	if result, err := t.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*models.TeamType), nil
	}
}

func (t teamTypeDo) Find() ([]*models.TeamType, error) {
	result, err := t.DO.Find()
	return result.([]*models.TeamType), err
}

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

func (t teamTypeDo) Attrs(attrs ...field.AssignExpr) ITeamTypeDo {
	return t.withDO(t.DO.Attrs(attrs...))
}

func (t teamTypeDo) Assign(attrs ...field.AssignExpr) ITeamTypeDo {
	return t.withDO(t.DO.Assign(attrs...))
}

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

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

func (t teamTypeDo) FirstOrInit() (*models.TeamType, error) {
	if result, err := t.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*models.TeamType), nil
	}
}

func (t teamTypeDo) FirstOrCreate() (*models.TeamType, error) {
	if result, err := t.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*models.TeamType), nil
	}
}

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

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

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

func (t teamTypeDo) Scan(result interface{}) (err error) {
	return t.DO.Scan(result)
}

func (t teamTypeDo) Delete(models ...*models.TeamType) (result gen.ResultInfo, err error) {
	return t.DO.Delete(models)
}

func (t *teamTypeDo) withDO(do gen.Dao) *teamTypeDo {
	t.DO = *do.(*gen.DO)
	return t
}
