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

	_sysDictionaryDetail.sysDictionaryDetailDo.UseDB(db, opts...)
	_sysDictionaryDetail.sysDictionaryDetailDo.UseModel(&model.SysDictionaryDetail{})

	tableName := _sysDictionaryDetail.sysDictionaryDetailDo.TableName()
	_sysDictionaryDetail.ALL = field.NewAsterisk(tableName)
	_sysDictionaryDetail.ID = field.NewInt64(tableName, "id")
	_sysDictionaryDetail.CreatedAt = field.NewTime(tableName, "created_at")
	_sysDictionaryDetail.UpdatedAt = field.NewTime(tableName, "updated_at")
	_sysDictionaryDetail.DeletedAt = field.NewField(tableName, "deleted_at")
	_sysDictionaryDetail.Label = field.NewString(tableName, "label")
	_sysDictionaryDetail.Value = field.NewString(tableName, "value")
	_sysDictionaryDetail.Extend = field.NewString(tableName, "extend")
	_sysDictionaryDetail.Status = field.NewBool(tableName, "status")
	_sysDictionaryDetail.Sort = field.NewInt64(tableName, "sort")
	_sysDictionaryDetail.SysDictionaryID = field.NewInt64(tableName, "sys_dictionary_id")
	_sysDictionaryDetail.ParentID = field.NewInt64(tableName, "parent_id")
	_sysDictionaryDetail.Level = field.NewInt64(tableName, "level")
	_sysDictionaryDetail.Path = field.NewString(tableName, "path")

	_sysDictionaryDetail.fillFieldMap()

	return _sysDictionaryDetail
}

type sysDictionaryDetail struct {
	sysDictionaryDetailDo sysDictionaryDetailDo

	ALL             field.Asterisk
	ID              field.Int64
	CreatedAt       field.Time
	UpdatedAt       field.Time
	DeletedAt       field.Field
	Label           field.String // 展示值
	Value           field.String // 字典值
	Extend          field.String // 扩展值
	Status          field.Bool   // 启用状态
	Sort            field.Int64  // 排序标记
	SysDictionaryID field.Int64  // 关联标记
	ParentID        field.Int64  // 父级字典详情ID
	Level           field.Int64  // 层级深度
	Path            field.String // 层级路径

	fieldMap map[string]field.Expr
}

func (s sysDictionaryDetail) Table(newTableName string) *sysDictionaryDetail {
	s.sysDictionaryDetailDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

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

func (s *sysDictionaryDetail) updateTableName(table string) *sysDictionaryDetail {
	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.Label = field.NewString(table, "label")
	s.Value = field.NewString(table, "value")
	s.Extend = field.NewString(table, "extend")
	s.Status = field.NewBool(table, "status")
	s.Sort = field.NewInt64(table, "sort")
	s.SysDictionaryID = field.NewInt64(table, "sys_dictionary_id")
	s.ParentID = field.NewInt64(table, "parent_id")
	s.Level = field.NewInt64(table, "level")
	s.Path = field.NewString(table, "path")

	s.fillFieldMap()

	return s
}

func (s *sysDictionaryDetail) WithContext(ctx context.Context) ISysDictionaryDetailDo {
	return s.sysDictionaryDetailDo.WithContext(ctx)
}

func (s sysDictionaryDetail) TableName() string { return s.sysDictionaryDetailDo.TableName() }

func (s sysDictionaryDetail) Alias() string { return s.sysDictionaryDetailDo.Alias() }

func (s sysDictionaryDetail) Columns(cols ...field.Expr) gen.Columns {
	return s.sysDictionaryDetailDo.Columns(cols...)
}

func (s *sysDictionaryDetail) 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 *sysDictionaryDetail) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 13)
	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["label"] = s.Label
	s.fieldMap["value"] = s.Value
	s.fieldMap["extend"] = s.Extend
	s.fieldMap["status"] = s.Status
	s.fieldMap["sort"] = s.Sort
	s.fieldMap["sys_dictionary_id"] = s.SysDictionaryID
	s.fieldMap["parent_id"] = s.ParentID
	s.fieldMap["level"] = s.Level
	s.fieldMap["path"] = s.Path
}

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

func (s sysDictionaryDetail) replaceDB(db *gorm.DB) sysDictionaryDetail {
	s.sysDictionaryDetailDo.ReplaceDB(db)
	return s
}

type sysDictionaryDetailDo struct{ gen.DO }

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

func (s sysDictionaryDetailDo) Debug() ISysDictionaryDetailDo {
	return s.withDO(s.DO.Debug())
}

func (s sysDictionaryDetailDo) WithContext(ctx context.Context) ISysDictionaryDetailDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysDictionaryDetailDo) ReadDB() ISysDictionaryDetailDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysDictionaryDetailDo) WriteDB() ISysDictionaryDetailDo {
	return s.Clauses(dbresolver.Write)
}

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

func (s sysDictionaryDetailDo) Clauses(conds ...clause.Expression) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sysDictionaryDetailDo) Not(conds ...gen.Condition) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysDictionaryDetailDo) Or(conds ...gen.Condition) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysDictionaryDetailDo) Select(conds ...field.Expr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysDictionaryDetailDo) Where(conds ...gen.Condition) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysDictionaryDetailDo) Order(conds ...field.Expr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysDictionaryDetailDo) Distinct(cols ...field.Expr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysDictionaryDetailDo) Omit(cols ...field.Expr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sysDictionaryDetailDo) Group(cols ...field.Expr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysDictionaryDetailDo) Having(conds ...gen.Condition) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysDictionaryDetailDo) Limit(limit int) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysDictionaryDetailDo) Offset(offset int) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysDictionaryDetailDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysDictionaryDetailDo) Unscoped() ISysDictionaryDetailDo {
	return s.withDO(s.DO.Unscoped())
}

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

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

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

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

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

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

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

func (s sysDictionaryDetailDo) Attrs(attrs ...field.AssignExpr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysDictionaryDetailDo) Assign(attrs ...field.AssignExpr) ISysDictionaryDetailDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

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

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

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

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

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