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

	"wechat-api/database/dao/wechat/model"
)

func newEmployeeConfig(db *gorm.DB, opts ...gen.DOOption) employeeConfig {
	_employeeConfig := employeeConfig{}

	_employeeConfig.employeeConfigDo.UseDB(db, opts...)
	_employeeConfig.employeeConfigDo.UseModel(&model.EmployeeConfig{})

	tableName := _employeeConfig.employeeConfigDo.TableName()
	_employeeConfig.ALL = field.NewAsterisk(tableName)
	_employeeConfig.ID = field.NewInt64(tableName, "id")
	_employeeConfig.CreatedAt = field.NewTime(tableName, "created_at")
	_employeeConfig.UpdatedAt = field.NewTime(tableName, "updated_at")
	_employeeConfig.DeletedAt = field.NewField(tableName, "deleted_at")
	_employeeConfig.Stype = field.NewString(tableName, "stype")
	_employeeConfig.Title = field.NewString(tableName, "title")
	_employeeConfig.Photo = field.NewString(tableName, "photo")
	_employeeConfig.OrganizationID = field.NewInt64(tableName, "organization_id")

	_employeeConfig.fillFieldMap()

	return _employeeConfig
}

type employeeConfig struct {
	employeeConfigDo

	ALL            field.Asterisk
	ID             field.Int64
	CreatedAt      field.Time   // Create Time | 创建日期
	UpdatedAt      field.Time   // Update Time | 修改日期
	DeletedAt      field.Field  // Delete Time | 删除日期
	Stype          field.String // 配置类型
	Title          field.String // 标题
	Photo          field.String // 图片
	OrganizationID field.Int64  // 机构 ID

	fieldMap map[string]field.Expr
}

func (e employeeConfig) Table(newTableName string) *employeeConfig {
	e.employeeConfigDo.UseTable(newTableName)
	return e.updateTableName(newTableName)
}

func (e employeeConfig) As(alias string) *employeeConfig {
	e.employeeConfigDo.DO = *(e.employeeConfigDo.As(alias).(*gen.DO))
	return e.updateTableName(alias)
}

func (e *employeeConfig) updateTableName(table string) *employeeConfig {
	e.ALL = field.NewAsterisk(table)
	e.ID = field.NewInt64(table, "id")
	e.CreatedAt = field.NewTime(table, "created_at")
	e.UpdatedAt = field.NewTime(table, "updated_at")
	e.DeletedAt = field.NewField(table, "deleted_at")
	e.Stype = field.NewString(table, "stype")
	e.Title = field.NewString(table, "title")
	e.Photo = field.NewString(table, "photo")
	e.OrganizationID = field.NewInt64(table, "organization_id")

	e.fillFieldMap()

	return e
}

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

func (e *employeeConfig) fillFieldMap() {
	e.fieldMap = make(map[string]field.Expr, 8)
	e.fieldMap["id"] = e.ID
	e.fieldMap["created_at"] = e.CreatedAt
	e.fieldMap["updated_at"] = e.UpdatedAt
	e.fieldMap["deleted_at"] = e.DeletedAt
	e.fieldMap["stype"] = e.Stype
	e.fieldMap["title"] = e.Title
	e.fieldMap["photo"] = e.Photo
	e.fieldMap["organization_id"] = e.OrganizationID
}

func (e employeeConfig) clone(db *gorm.DB) employeeConfig {
	e.employeeConfigDo.ReplaceConnPool(db.Statement.ConnPool)
	return e
}

func (e employeeConfig) replaceDB(db *gorm.DB) employeeConfig {
	e.employeeConfigDo.ReplaceDB(db)
	return e
}

type employeeConfigDo struct{ gen.DO }

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

func (e employeeConfigDo) Debug() IEmployeeConfigDo {
	return e.withDO(e.DO.Debug())
}

func (e employeeConfigDo) WithContext(ctx context.Context) IEmployeeConfigDo {
	return e.withDO(e.DO.WithContext(ctx))
}

func (e employeeConfigDo) ReadDB() IEmployeeConfigDo {
	return e.Clauses(dbresolver.Read)
}

func (e employeeConfigDo) WriteDB() IEmployeeConfigDo {
	return e.Clauses(dbresolver.Write)
}

func (e employeeConfigDo) Session(config *gorm.Session) IEmployeeConfigDo {
	return e.withDO(e.DO.Session(config))
}

func (e employeeConfigDo) Clauses(conds ...clause.Expression) IEmployeeConfigDo {
	return e.withDO(e.DO.Clauses(conds...))
}

func (e employeeConfigDo) Returning(value interface{}, columns ...string) IEmployeeConfigDo {
	return e.withDO(e.DO.Returning(value, columns...))
}

func (e employeeConfigDo) Not(conds ...gen.Condition) IEmployeeConfigDo {
	return e.withDO(e.DO.Not(conds...))
}

func (e employeeConfigDo) Or(conds ...gen.Condition) IEmployeeConfigDo {
	return e.withDO(e.DO.Or(conds...))
}

func (e employeeConfigDo) Select(conds ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.Select(conds...))
}

func (e employeeConfigDo) Where(conds ...gen.Condition) IEmployeeConfigDo {
	return e.withDO(e.DO.Where(conds...))
}

func (e employeeConfigDo) Order(conds ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.Order(conds...))
}

func (e employeeConfigDo) Distinct(cols ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.Distinct(cols...))
}

func (e employeeConfigDo) Omit(cols ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.Omit(cols...))
}

func (e employeeConfigDo) Join(table schema.Tabler, on ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.Join(table, on...))
}

func (e employeeConfigDo) LeftJoin(table schema.Tabler, on ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.LeftJoin(table, on...))
}

func (e employeeConfigDo) RightJoin(table schema.Tabler, on ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.RightJoin(table, on...))
}

func (e employeeConfigDo) Group(cols ...field.Expr) IEmployeeConfigDo {
	return e.withDO(e.DO.Group(cols...))
}

func (e employeeConfigDo) Having(conds ...gen.Condition) IEmployeeConfigDo {
	return e.withDO(e.DO.Having(conds...))
}

func (e employeeConfigDo) Limit(limit int) IEmployeeConfigDo {
	return e.withDO(e.DO.Limit(limit))
}

func (e employeeConfigDo) Offset(offset int) IEmployeeConfigDo {
	return e.withDO(e.DO.Offset(offset))
}

func (e employeeConfigDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IEmployeeConfigDo {
	return e.withDO(e.DO.Scopes(funcs...))
}

func (e employeeConfigDo) Unscoped() IEmployeeConfigDo {
	return e.withDO(e.DO.Unscoped())
}

func (e employeeConfigDo) Create(values ...*model.EmployeeConfig) error {
	if len(values) == 0 {
		return nil
	}
	return e.DO.Create(values)
}

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

func (e employeeConfigDo) First() (*model.EmployeeConfig, error) {
	if result, err := e.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.EmployeeConfig), nil
	}
}

func (e employeeConfigDo) Take() (*model.EmployeeConfig, error) {
	if result, err := e.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.EmployeeConfig), nil
	}
}

func (e employeeConfigDo) Last() (*model.EmployeeConfig, error) {
	if result, err := e.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.EmployeeConfig), nil
	}
}

func (e employeeConfigDo) Find() ([]*model.EmployeeConfig, error) {
	result, err := e.DO.Find()
	return result.([]*model.EmployeeConfig), err
}

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

func (e employeeConfigDo) Attrs(attrs ...field.AssignExpr) IEmployeeConfigDo {
	return e.withDO(e.DO.Attrs(attrs...))
}

func (e employeeConfigDo) Assign(attrs ...field.AssignExpr) IEmployeeConfigDo {
	return e.withDO(e.DO.Assign(attrs...))
}

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

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

func (e employeeConfigDo) FirstOrInit() (*model.EmployeeConfig, error) {
	if result, err := e.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.EmployeeConfig), nil
	}
}

func (e employeeConfigDo) FirstOrCreate() (*model.EmployeeConfig, error) {
	if result, err := e.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.EmployeeConfig), nil
	}
}

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

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

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

func (e employeeConfigDo) Scan(result interface{}) (err error) {
	return e.DO.Scan(result)
}

func (e employeeConfigDo) Delete(models ...*model.EmployeeConfig) (result gen.ResultInfo, err error) {
	return e.DO.Delete(models)
}

func (e *employeeConfigDo) withDO(do gen.Dao) *employeeConfigDo {
	e.DO = *do.(*gen.DO)
	return e
}
