// 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"
	"database/sql"

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

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

	"gorm.io/plugin/dbresolver"

	"kra/internal/data/model"
)

func newSysBaseMenuParameter(db *gorm.DB, opts ...gen.DOOption) sysBaseMenuParameter {
	_sysBaseMenuParameter := sysBaseMenuParameter{}

	_sysBaseMenuParameter.sysBaseMenuParameterDo.UseDB(db, opts...)
	_sysBaseMenuParameter.sysBaseMenuParameterDo.UseModel(&model.SysBaseMenuParameter{})

	tableName := _sysBaseMenuParameter.sysBaseMenuParameterDo.TableName()
	_sysBaseMenuParameter.ALL = field.NewAsterisk(tableName)
	_sysBaseMenuParameter.ID = field.NewInt64(tableName, "id")
	_sysBaseMenuParameter.CreatedAt = field.NewTime(tableName, "created_at")
	_sysBaseMenuParameter.UpdatedAt = field.NewTime(tableName, "updated_at")
	_sysBaseMenuParameter.DeletedAt = field.NewField(tableName, "deleted_at")
	_sysBaseMenuParameter.SysBaseMenuID = field.NewInt64(tableName, "sys_base_menu_id")
	_sysBaseMenuParameter.Type = field.NewString(tableName, "type")
	_sysBaseMenuParameter.Key = field.NewString(tableName, "key")
	_sysBaseMenuParameter.Value = field.NewString(tableName, "value")

	_sysBaseMenuParameter.fillFieldMap()

	return _sysBaseMenuParameter
}

type sysBaseMenuParameter struct {
	sysBaseMenuParameterDo sysBaseMenuParameterDo

	ALL           field.Asterisk
	ID            field.Int64
	CreatedAt     field.Time
	UpdatedAt     field.Time
	DeletedAt     field.Field
	SysBaseMenuID field.Int64
	Type          field.String // 地址栏携带参数为params还是query
	Key           field.String // 地址栏携带参数的key
	Value         field.String // 地址栏携带参数的值

	fieldMap map[string]field.Expr
}

func (s sysBaseMenuParameter) Table(newTableName string) *sysBaseMenuParameter {
	s.sysBaseMenuParameterDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

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

func (s *sysBaseMenuParameter) updateTableName(table string) *sysBaseMenuParameter {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt64(table, "id")
	s.CreatedAt = field.NewTime(table, "created_at")
	s.UpdatedAt = field.NewTime(table, "updated_at")
	s.DeletedAt = field.NewField(table, "deleted_at")
	s.SysBaseMenuID = field.NewInt64(table, "sys_base_menu_id")
	s.Type = field.NewString(table, "type")
	s.Key = field.NewString(table, "key")
	s.Value = field.NewString(table, "value")

	s.fillFieldMap()

	return s
}

func (s *sysBaseMenuParameter) WithContext(ctx context.Context) ISysBaseMenuParameterDo {
	return s.sysBaseMenuParameterDo.WithContext(ctx)
}

func (s sysBaseMenuParameter) TableName() string { return s.sysBaseMenuParameterDo.TableName() }

func (s sysBaseMenuParameter) Alias() string { return s.sysBaseMenuParameterDo.Alias() }

func (s sysBaseMenuParameter) Columns(cols ...field.Expr) gen.Columns {
	return s.sysBaseMenuParameterDo.Columns(cols...)
}

func (s *sysBaseMenuParameter) 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 *sysBaseMenuParameter) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 8)
	s.fieldMap["id"] = s.ID
	s.fieldMap["created_at"] = s.CreatedAt
	s.fieldMap["updated_at"] = s.UpdatedAt
	s.fieldMap["deleted_at"] = s.DeletedAt
	s.fieldMap["sys_base_menu_id"] = s.SysBaseMenuID
	s.fieldMap["type"] = s.Type
	s.fieldMap["key"] = s.Key
	s.fieldMap["value"] = s.Value
}

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

func (s sysBaseMenuParameter) replaceDB(db *gorm.DB) sysBaseMenuParameter {
	s.sysBaseMenuParameterDo.ReplaceDB(db)
	return s
}

type sysBaseMenuParameterDo struct{ gen.DO }

type ISysBaseMenuParameterDo interface {
	gen.SubQuery
	Debug() ISysBaseMenuParameterDo
	WithContext(ctx context.Context) ISysBaseMenuParameterDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() ISysBaseMenuParameterDo
	WriteDB() ISysBaseMenuParameterDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) ISysBaseMenuParameterDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) ISysBaseMenuParameterDo
	Not(conds ...gen.Condition) ISysBaseMenuParameterDo
	Or(conds ...gen.Condition) ISysBaseMenuParameterDo
	Select(conds ...field.Expr) ISysBaseMenuParameterDo
	Where(conds ...gen.Condition) ISysBaseMenuParameterDo
	Order(conds ...field.Expr) ISysBaseMenuParameterDo
	Distinct(cols ...field.Expr) ISysBaseMenuParameterDo
	Omit(cols ...field.Expr) ISysBaseMenuParameterDo
	Join(table schema.Tabler, on ...field.Expr) ISysBaseMenuParameterDo
	LeftJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuParameterDo
	RightJoin(table schema.Tabler, on ...field.Expr) ISysBaseMenuParameterDo
	Group(cols ...field.Expr) ISysBaseMenuParameterDo
	Having(conds ...gen.Condition) ISysBaseMenuParameterDo
	Limit(limit int) ISysBaseMenuParameterDo
	Offset(offset int) ISysBaseMenuParameterDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) ISysBaseMenuParameterDo
	Unscoped() ISysBaseMenuParameterDo
	Create(values ...*model.SysBaseMenuParameter) error
	CreateInBatches(values []*model.SysBaseMenuParameter, batchSize int) error
	Save(values ...*model.SysBaseMenuParameter) error
	First() (*model.SysBaseMenuParameter, error)
	Take() (*model.SysBaseMenuParameter, error)
	Last() (*model.SysBaseMenuParameter, error)
	Find() ([]*model.SysBaseMenuParameter, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SysBaseMenuParameter, err error)
	FindInBatches(result *[]*model.SysBaseMenuParameter, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.SysBaseMenuParameter) (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) ISysBaseMenuParameterDo
	Assign(attrs ...field.AssignExpr) ISysBaseMenuParameterDo
	Joins(fields ...field.RelationField) ISysBaseMenuParameterDo
	Preload(fields ...field.RelationField) ISysBaseMenuParameterDo
	FirstOrInit() (*model.SysBaseMenuParameter, error)
	FirstOrCreate() (*model.SysBaseMenuParameter, error)
	FindByPage(offset int, limit int) (result []*model.SysBaseMenuParameter, count int64, err error)
	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
	Rows() (*sql.Rows, error)
	Row() *sql.Row
	Scan(result interface{}) (err error)
	Returning(value interface{}, columns ...string) ISysBaseMenuParameterDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (s sysBaseMenuParameterDo) Debug() ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Debug())
}

func (s sysBaseMenuParameterDo) WithContext(ctx context.Context) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysBaseMenuParameterDo) ReadDB() ISysBaseMenuParameterDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysBaseMenuParameterDo) WriteDB() ISysBaseMenuParameterDo {
	return s.Clauses(dbresolver.Write)
}

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

func (s sysBaseMenuParameterDo) Clauses(conds ...clause.Expression) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sysBaseMenuParameterDo) Not(conds ...gen.Condition) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysBaseMenuParameterDo) Or(conds ...gen.Condition) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysBaseMenuParameterDo) Select(conds ...field.Expr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysBaseMenuParameterDo) Where(conds ...gen.Condition) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysBaseMenuParameterDo) Order(conds ...field.Expr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysBaseMenuParameterDo) Distinct(cols ...field.Expr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysBaseMenuParameterDo) Omit(cols ...field.Expr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sysBaseMenuParameterDo) Group(cols ...field.Expr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysBaseMenuParameterDo) Having(conds ...gen.Condition) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysBaseMenuParameterDo) Limit(limit int) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysBaseMenuParameterDo) Offset(offset int) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysBaseMenuParameterDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysBaseMenuParameterDo) Unscoped() ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Unscoped())
}

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

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

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

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

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

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

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

func (s sysBaseMenuParameterDo) Attrs(attrs ...field.AssignExpr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysBaseMenuParameterDo) Assign(attrs ...field.AssignExpr) ISysBaseMenuParameterDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

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

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

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

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

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