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

	_adminSystem.adminSystemDo.UseDB(db, opts...)
	_adminSystem.adminSystemDo.UseModel(&model.AdminSystem{})

	tableName := _adminSystem.adminSystemDo.TableName()
	_adminSystem.ALL = field.NewAsterisk(tableName)
	_adminSystem.ID = field.NewInt32(tableName, "id")
	_adminSystem.Name = field.NewString(tableName, "name")
	_adminSystem.URL = field.NewString(tableName, "url")
	_adminSystem.CreateAt = field.NewInt32(tableName, "create_at")
	_adminSystem.UpdateAt = field.NewInt32(tableName, "update_at")

	_adminSystem.fillFieldMap()

	return _adminSystem
}

type adminSystem struct {
	adminSystemDo

	ALL      field.Asterisk
	ID       field.Int32
	Name     field.String
	URL      field.String
	CreateAt field.Int32
	UpdateAt field.Int32

	fieldMap map[string]field.Expr
}

func (a adminSystem) Table(newTableName string) *adminSystem {
	a.adminSystemDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a adminSystem) As(alias string) *adminSystem {
	a.adminSystemDo.DO = *(a.adminSystemDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *adminSystem) updateTableName(table string) *adminSystem {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt32(table, "id")
	a.Name = field.NewString(table, "name")
	a.URL = field.NewString(table, "url")
	a.CreateAt = field.NewInt32(table, "create_at")
	a.UpdateAt = field.NewInt32(table, "update_at")

	a.fillFieldMap()

	return a
}

func (a *adminSystem) WithContext(ctx context.Context) *adminSystemDo {
	return a.adminSystemDo.WithContext(ctx)
}

func (a adminSystem) TableName() string { return a.adminSystemDo.TableName() }

func (a adminSystem) Alias() string { return a.adminSystemDo.Alias() }

func (a adminSystem) Columns(cols ...field.Expr) gen.Columns { return a.adminSystemDo.Columns(cols...) }

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

func (a *adminSystem) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 5)
	a.fieldMap["id"] = a.ID
	a.fieldMap["name"] = a.Name
	a.fieldMap["url"] = a.URL
	a.fieldMap["create_at"] = a.CreateAt
	a.fieldMap["update_at"] = a.UpdateAt
}

func (a adminSystem) clone(db *gorm.DB) adminSystem {
	a.adminSystemDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a adminSystem) replaceDB(db *gorm.DB) adminSystem {
	a.adminSystemDo.ReplaceDB(db)
	return a
}

type adminSystemDo struct{ gen.DO }

func (a adminSystemDo) Debug() *adminSystemDo {
	return a.withDO(a.DO.Debug())
}

func (a adminSystemDo) WithContext(ctx context.Context) *adminSystemDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a adminSystemDo) ReadDB() *adminSystemDo {
	return a.Clauses(dbresolver.Read)
}

func (a adminSystemDo) WriteDB() *adminSystemDo {
	return a.Clauses(dbresolver.Write)
}

func (a adminSystemDo) Session(config *gorm.Session) *adminSystemDo {
	return a.withDO(a.DO.Session(config))
}

func (a adminSystemDo) Clauses(conds ...clause.Expression) *adminSystemDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a adminSystemDo) Not(conds ...gen.Condition) *adminSystemDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a adminSystemDo) Or(conds ...gen.Condition) *adminSystemDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a adminSystemDo) Select(conds ...field.Expr) *adminSystemDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a adminSystemDo) Where(conds ...gen.Condition) *adminSystemDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a adminSystemDo) Order(conds ...field.Expr) *adminSystemDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a adminSystemDo) Distinct(cols ...field.Expr) *adminSystemDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a adminSystemDo) Omit(cols ...field.Expr) *adminSystemDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a adminSystemDo) Group(cols ...field.Expr) *adminSystemDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a adminSystemDo) Having(conds ...gen.Condition) *adminSystemDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a adminSystemDo) Limit(limit int) *adminSystemDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a adminSystemDo) Offset(offset int) *adminSystemDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a adminSystemDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *adminSystemDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a adminSystemDo) Unscoped() *adminSystemDo {
	return a.withDO(a.DO.Unscoped())
}

func (a adminSystemDo) Create(values ...*model.AdminSystem) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

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

func (a adminSystemDo) First() (*model.AdminSystem, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminSystem), nil
	}
}

func (a adminSystemDo) Take() (*model.AdminSystem, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminSystem), nil
	}
}

func (a adminSystemDo) Last() (*model.AdminSystem, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminSystem), nil
	}
}

func (a adminSystemDo) Find() ([]*model.AdminSystem, error) {
	result, err := a.DO.Find()
	return result.([]*model.AdminSystem), err
}

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

func (a adminSystemDo) Attrs(attrs ...field.AssignExpr) *adminSystemDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a adminSystemDo) Assign(attrs ...field.AssignExpr) *adminSystemDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

func (a adminSystemDo) FirstOrInit() (*model.AdminSystem, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminSystem), nil
	}
}

func (a adminSystemDo) FirstOrCreate() (*model.AdminSystem, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.AdminSystem), nil
	}
}

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

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

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

func (a adminSystemDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a adminSystemDo) Delete(models ...*model.AdminSystem) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *adminSystemDo) withDO(do gen.Dao) *adminSystemDo {
	a.DO = *do.(*gen.DO)
	return a
}
