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

	_adminOperation.adminOperationDo.UseDB(db, opts...)
	_adminOperation.adminOperationDo.UseModel(&model.AdminOperation{})

	tableName := _adminOperation.adminOperationDo.TableName()
	_adminOperation.ALL = field.NewAsterisk(tableName)
	_adminOperation.ID = field.NewInt32(tableName, "id")
	_adminOperation.Name = field.NewString(tableName, "name")
	_adminOperation.API = field.NewString(tableName, "api")

	_adminOperation.fillFieldMap()

	return _adminOperation
}

type adminOperation struct {
	adminOperationDo adminOperationDo

	ALL  field.Asterisk
	ID   field.Int32
	Name field.String // 操作名称
	API  field.String // 接口路由

	fieldMap map[string]field.Expr
}

func (a adminOperation) Table(newTableName string) *adminOperation {
	a.adminOperationDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

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

func (a *adminOperation) updateTableName(table string) *adminOperation {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt32(table, "id")
	a.Name = field.NewString(table, "name")
	a.API = field.NewString(table, "api")

	a.fillFieldMap()

	return a
}

func (a *adminOperation) WithContext(ctx context.Context) *adminOperationDo {
	return a.adminOperationDo.WithContext(ctx)
}

func (a adminOperation) TableName() string { return a.adminOperationDo.TableName() }

func (a adminOperation) Alias() string { return a.adminOperationDo.Alias() }

func (a adminOperation) Columns(cols ...field.Expr) gen.Columns {
	return a.adminOperationDo.Columns(cols...)
}

func (a *adminOperation) 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 *adminOperation) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 3)
	a.fieldMap["id"] = a.ID
	a.fieldMap["name"] = a.Name
	a.fieldMap["api"] = a.API
}

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

func (a adminOperation) replaceDB(db *gorm.DB) adminOperation {
	a.adminOperationDo.ReplaceDB(db)
	return a
}

type adminOperationDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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