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

	"github.com/ch3nnn/webstack-go/internal/dal/model"
)

func newSysConfig(db *gorm.DB, opts ...gen.DOOption) sysConfig {
	_sysConfig := sysConfig{}

	_sysConfig.sysConfigDo.UseDB(db, opts...)
	_sysConfig.sysConfigDo.UseModel(&model.SysConfig{})

	tableName := _sysConfig.sysConfigDo.TableName()
	_sysConfig.ALL = field.NewAsterisk(tableName)
	_sysConfig.ID = field.NewInt(tableName, "id")
	_sysConfig.AboutSite = field.NewString(tableName, "about_site")
	_sysConfig.AboutAuthor = field.NewString(tableName, "about_author")
	_sysConfig.IsAbout = field.NewBool(tableName, "is_about")
	_sysConfig.SiteTitle = field.NewString(tableName, "site_title")
	_sysConfig.SiteKeyword = field.NewString(tableName, "site_keyword")
	_sysConfig.SiteDesc = field.NewString(tableName, "site_desc")
	_sysConfig.SiteRecord = field.NewString(tableName, "site_record")
	_sysConfig.SiteLogo = field.NewString(tableName, "site_logo")
	_sysConfig.SiteFavicon = field.NewString(tableName, "site_favicon")
	_sysConfig.SiteURL = field.NewString(tableName, "site_url")

	_sysConfig.fillFieldMap()

	return _sysConfig
}

type sysConfig struct {
	sysConfigDo sysConfigDo

	ALL         field.Asterisk
	ID          field.Int
	AboutSite   field.String
	AboutAuthor field.String
	IsAbout     field.Bool
	SiteTitle   field.String
	SiteKeyword field.String
	SiteDesc    field.String
	SiteRecord  field.String
	SiteLogo    field.String
	SiteFavicon field.String
	SiteURL     field.String

	fieldMap map[string]field.Expr
}

func (s sysConfig) Table(newTableName string) *sysConfig {
	s.sysConfigDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

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

func (s *sysConfig) updateTableName(table string) *sysConfig {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt(table, "id")
	s.AboutSite = field.NewString(table, "about_site")
	s.AboutAuthor = field.NewString(table, "about_author")
	s.IsAbout = field.NewBool(table, "is_about")
	s.SiteTitle = field.NewString(table, "site_title")
	s.SiteKeyword = field.NewString(table, "site_keyword")
	s.SiteDesc = field.NewString(table, "site_desc")
	s.SiteRecord = field.NewString(table, "site_record")
	s.SiteLogo = field.NewString(table, "site_logo")
	s.SiteFavicon = field.NewString(table, "site_favicon")
	s.SiteURL = field.NewString(table, "site_url")

	s.fillFieldMap()

	return s
}

func (s *sysConfig) WithContext(ctx context.Context) ISysConfigDo {
	return s.sysConfigDo.WithContext(ctx)
}

func (s sysConfig) TableName() string { return s.sysConfigDo.TableName() }

func (s sysConfig) Alias() string { return s.sysConfigDo.Alias() }

func (s sysConfig) Columns(cols ...field.Expr) gen.Columns { return s.sysConfigDo.Columns(cols...) }

func (s *sysConfig) 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 *sysConfig) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 11)
	s.fieldMap["id"] = s.ID
	s.fieldMap["about_site"] = s.AboutSite
	s.fieldMap["about_author"] = s.AboutAuthor
	s.fieldMap["is_about"] = s.IsAbout
	s.fieldMap["site_title"] = s.SiteTitle
	s.fieldMap["site_keyword"] = s.SiteKeyword
	s.fieldMap["site_desc"] = s.SiteDesc
	s.fieldMap["site_record"] = s.SiteRecord
	s.fieldMap["site_logo"] = s.SiteLogo
	s.fieldMap["site_favicon"] = s.SiteFavicon
	s.fieldMap["site_url"] = s.SiteURL
}

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

func (s sysConfig) replaceDB(db *gorm.DB) sysConfig {
	s.sysConfigDo.ReplaceDB(db)
	return s
}

type sysConfigDo struct{ gen.DO }

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

func (s sysConfigDo) Debug() ISysConfigDo {
	return s.withDO(s.DO.Debug())
}

func (s sysConfigDo) WithContext(ctx context.Context) ISysConfigDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysConfigDo) ReadDB() ISysConfigDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysConfigDo) WriteDB() ISysConfigDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysConfigDo) Session(config *gorm.Session) ISysConfigDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysConfigDo) Clauses(conds ...clause.Expression) ISysConfigDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sysConfigDo) Not(conds ...gen.Condition) ISysConfigDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysConfigDo) Or(conds ...gen.Condition) ISysConfigDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysConfigDo) Select(conds ...field.Expr) ISysConfigDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysConfigDo) Where(conds ...gen.Condition) ISysConfigDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysConfigDo) Order(conds ...field.Expr) ISysConfigDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysConfigDo) Distinct(cols ...field.Expr) ISysConfigDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysConfigDo) Omit(cols ...field.Expr) ISysConfigDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sysConfigDo) Group(cols ...field.Expr) ISysConfigDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysConfigDo) Having(conds ...gen.Condition) ISysConfigDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysConfigDo) Limit(limit int) ISysConfigDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysConfigDo) Offset(offset int) ISysConfigDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysConfigDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysConfigDo) Unscoped() ISysConfigDo {
	return s.withDO(s.DO.Unscoped())
}

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

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

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

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

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

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

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

func (s sysConfigDo) Attrs(attrs ...field.AssignExpr) ISysConfigDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysConfigDo) Assign(attrs ...field.AssignExpr) ISysConfigDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

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

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

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

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

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