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

	_employee.employeeDo.UseDB(db, opts...)
	_employee.employeeDo.UseModel(&model.Employee{})

	tableName := _employee.employeeDo.TableName()
	_employee.ALL = field.NewAsterisk(tableName)
	_employee.ID = field.NewInt64(tableName, "id")
	_employee.CreatedAt = field.NewTime(tableName, "created_at")
	_employee.UpdatedAt = field.NewTime(tableName, "updated_at")
	_employee.DeletedAt = field.NewField(tableName, "deleted_at")
	_employee.Title = field.NewString(tableName, "title")
	_employee.Avatar = field.NewString(tableName, "avatar")
	_employee.Tags = field.NewString(tableName, "tags")
	_employee.HireCount = field.NewInt64(tableName, "hire_count")
	_employee.ServiceCount = field.NewInt64(tableName, "service_count")
	_employee.AchievementCount = field.NewInt64(tableName, "achievement_count")
	_employee.Intro = field.NewString(tableName, "intro")
	_employee.Estimate = field.NewString(tableName, "estimate")
	_employee.Skill = field.NewString(tableName, "skill")
	_employee.AbilityType = field.NewString(tableName, "ability_type")
	_employee.Scene = field.NewString(tableName, "scene")
	_employee.SwitchIn = field.NewString(tableName, "switch_in")
	_employee.Tutorial = field.NewString(tableName, "tutorial")
	_employee.VideoURL = field.NewString(tableName, "video_url")
	_employee.OrganizationID = field.NewInt64(tableName, "organization_id")
	_employee.CategoryID = field.NewInt64(tableName, "category_id")
	_employee.APIBase = field.NewString(tableName, "api_base")
	_employee.APIKey = field.NewString(tableName, "api_key")
	_employee.IsVip = field.NewInt64(tableName, "is_vip")
	_employee.AiInfo = field.NewString(tableName, "ai_info")
	_employee.ChatURL = field.NewString(tableName, "chat_url")

	_employee.fillFieldMap()

	return _employee
}

// employee 数字员工表
type employee struct {
	employeeDo

	ALL              field.Asterisk
	ID               field.Int64  // ID
	CreatedAt        field.Time   // 创建时间
	UpdatedAt        field.Time   // 修改时间
	DeletedAt        field.Field  // 删除时间
	Title            field.String // 标题
	Avatar           field.String // 头像URL
	Tags             field.String // Tag列表 用,连接多个
	HireCount        field.Int64  // 被雇佣次数
	ServiceCount     field.Int64  // 服务次数
	AchievementCount field.Int64  // 业绩单数
	Intro            field.String // 个人介绍
	Estimate         field.String // 自我评价
	Skill            field.String // 技能卡
	AbilityType      field.String // 能力类型 用,连接
	Scene            field.String // 使用场景 用,连接
	SwitchIn         field.String // 支持接入 用,连接
	Tutorial         field.String // 使用教程
	VideoURL         field.String // 视频
	OrganizationID   field.Int64  // 机构ID
	CategoryID       field.Int64  // 分类ID
	APIBase          field.String
	APIKey           field.String
	IsVip            field.Int64  // 是否VIP：0-否 1-是
	AiInfo           field.String // AI信息
	ChatURL          field.String // 聊天URL

	fieldMap map[string]field.Expr
}

func (e employee) Table(newTableName string) *employee {
	e.employeeDo.UseTable(newTableName)
	return e.updateTableName(newTableName)
}

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

func (e *employee) updateTableName(table string) *employee {
	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.Title = field.NewString(table, "title")
	e.Avatar = field.NewString(table, "avatar")
	e.Tags = field.NewString(table, "tags")
	e.HireCount = field.NewInt64(table, "hire_count")
	e.ServiceCount = field.NewInt64(table, "service_count")
	e.AchievementCount = field.NewInt64(table, "achievement_count")
	e.Intro = field.NewString(table, "intro")
	e.Estimate = field.NewString(table, "estimate")
	e.Skill = field.NewString(table, "skill")
	e.AbilityType = field.NewString(table, "ability_type")
	e.Scene = field.NewString(table, "scene")
	e.SwitchIn = field.NewString(table, "switch_in")
	e.Tutorial = field.NewString(table, "tutorial")
	e.VideoURL = field.NewString(table, "video_url")
	e.OrganizationID = field.NewInt64(table, "organization_id")
	e.CategoryID = field.NewInt64(table, "category_id")
	e.APIBase = field.NewString(table, "api_base")
	e.APIKey = field.NewString(table, "api_key")
	e.IsVip = field.NewInt64(table, "is_vip")
	e.AiInfo = field.NewString(table, "ai_info")
	e.ChatURL = field.NewString(table, "chat_url")

	e.fillFieldMap()

	return e
}

func (e *employee) 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 *employee) fillFieldMap() {
	e.fieldMap = make(map[string]field.Expr, 25)
	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["title"] = e.Title
	e.fieldMap["avatar"] = e.Avatar
	e.fieldMap["tags"] = e.Tags
	e.fieldMap["hire_count"] = e.HireCount
	e.fieldMap["service_count"] = e.ServiceCount
	e.fieldMap["achievement_count"] = e.AchievementCount
	e.fieldMap["intro"] = e.Intro
	e.fieldMap["estimate"] = e.Estimate
	e.fieldMap["skill"] = e.Skill
	e.fieldMap["ability_type"] = e.AbilityType
	e.fieldMap["scene"] = e.Scene
	e.fieldMap["switch_in"] = e.SwitchIn
	e.fieldMap["tutorial"] = e.Tutorial
	e.fieldMap["video_url"] = e.VideoURL
	e.fieldMap["organization_id"] = e.OrganizationID
	e.fieldMap["category_id"] = e.CategoryID
	e.fieldMap["api_base"] = e.APIBase
	e.fieldMap["api_key"] = e.APIKey
	e.fieldMap["is_vip"] = e.IsVip
	e.fieldMap["ai_info"] = e.AiInfo
	e.fieldMap["chat_url"] = e.ChatURL
}

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

func (e employee) replaceDB(db *gorm.DB) employee {
	e.employeeDo.ReplaceDB(db)
	return e
}

type employeeDo struct{ gen.DO }

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

func (e employeeDo) Debug() IEmployeeDo {
	return e.withDO(e.DO.Debug())
}

func (e employeeDo) WithContext(ctx context.Context) IEmployeeDo {
	return e.withDO(e.DO.WithContext(ctx))
}

func (e employeeDo) ReadDB() IEmployeeDo {
	return e.Clauses(dbresolver.Read)
}

func (e employeeDo) WriteDB() IEmployeeDo {
	return e.Clauses(dbresolver.Write)
}

func (e employeeDo) Session(config *gorm.Session) IEmployeeDo {
	return e.withDO(e.DO.Session(config))
}

func (e employeeDo) Clauses(conds ...clause.Expression) IEmployeeDo {
	return e.withDO(e.DO.Clauses(conds...))
}

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

func (e employeeDo) Not(conds ...gen.Condition) IEmployeeDo {
	return e.withDO(e.DO.Not(conds...))
}

func (e employeeDo) Or(conds ...gen.Condition) IEmployeeDo {
	return e.withDO(e.DO.Or(conds...))
}

func (e employeeDo) Select(conds ...field.Expr) IEmployeeDo {
	return e.withDO(e.DO.Select(conds...))
}

func (e employeeDo) Where(conds ...gen.Condition) IEmployeeDo {
	return e.withDO(e.DO.Where(conds...))
}

func (e employeeDo) Order(conds ...field.Expr) IEmployeeDo {
	return e.withDO(e.DO.Order(conds...))
}

func (e employeeDo) Distinct(cols ...field.Expr) IEmployeeDo {
	return e.withDO(e.DO.Distinct(cols...))
}

func (e employeeDo) Omit(cols ...field.Expr) IEmployeeDo {
	return e.withDO(e.DO.Omit(cols...))
}

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

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

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

func (e employeeDo) Group(cols ...field.Expr) IEmployeeDo {
	return e.withDO(e.DO.Group(cols...))
}

func (e employeeDo) Having(conds ...gen.Condition) IEmployeeDo {
	return e.withDO(e.DO.Having(conds...))
}

func (e employeeDo) Limit(limit int) IEmployeeDo {
	return e.withDO(e.DO.Limit(limit))
}

func (e employeeDo) Offset(offset int) IEmployeeDo {
	return e.withDO(e.DO.Offset(offset))
}

func (e employeeDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IEmployeeDo {
	return e.withDO(e.DO.Scopes(funcs...))
}

func (e employeeDo) Unscoped() IEmployeeDo {
	return e.withDO(e.DO.Unscoped())
}

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

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

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

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

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

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

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

func (e employeeDo) Attrs(attrs ...field.AssignExpr) IEmployeeDo {
	return e.withDO(e.DO.Attrs(attrs...))
}

func (e employeeDo) Assign(attrs ...field.AssignExpr) IEmployeeDo {
	return e.withDO(e.DO.Assign(attrs...))
}

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

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

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

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

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

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

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