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

	_workExperience.workExperienceDo.UseDB(db, opts...)
	_workExperience.workExperienceDo.UseModel(&model.WorkExperience{})

	tableName := _workExperience.workExperienceDo.TableName()
	_workExperience.ALL = field.NewAsterisk(tableName)
	_workExperience.ID = field.NewInt64(tableName, "id")
	_workExperience.EmployeeID = field.NewInt64(tableName, "employee_id")
	_workExperience.CreatedAt = field.NewTime(tableName, "created_at")
	_workExperience.UpdatedAt = field.NewTime(tableName, "updated_at")
	_workExperience.DeletedAt = field.NewField(tableName, "deleted_at")
	_workExperience.StartDate = field.NewTime(tableName, "start_date")
	_workExperience.EndDate = field.NewTime(tableName, "end_date")
	_workExperience.Company = field.NewString(tableName, "company")
	_workExperience.Experience = field.NewString(tableName, "experience")
	_workExperience.OrganizationID = field.NewInt64(tableName, "organization_id")

	_workExperience.fillFieldMap()

	return _workExperience
}

// workExperience 数字员工工作经验表
type workExperience struct {
	workExperienceDo

	ALL            field.Asterisk
	ID             field.Int64
	EmployeeID     field.Int64  // 员工ID
	CreatedAt      field.Time   // Create Time | 创建日期
	UpdatedAt      field.Time   // Update Time | 修改日期
	DeletedAt      field.Field  // Delete Time | 删除日期
	StartDate      field.Time   // 开始时间
	EndDate        field.Time   // 结束时间
	Company        field.String // 公司名
	Experience     field.String // 工作内容
	OrganizationID field.Int64  // 机构ID

	fieldMap map[string]field.Expr
}

func (w workExperience) Table(newTableName string) *workExperience {
	w.workExperienceDo.UseTable(newTableName)
	return w.updateTableName(newTableName)
}

func (w workExperience) As(alias string) *workExperience {
	w.workExperienceDo.DO = *(w.workExperienceDo.As(alias).(*gen.DO))
	return w.updateTableName(alias)
}

func (w *workExperience) updateTableName(table string) *workExperience {
	w.ALL = field.NewAsterisk(table)
	w.ID = field.NewInt64(table, "id")
	w.EmployeeID = field.NewInt64(table, "employee_id")
	w.CreatedAt = field.NewTime(table, "created_at")
	w.UpdatedAt = field.NewTime(table, "updated_at")
	w.DeletedAt = field.NewField(table, "deleted_at")
	w.StartDate = field.NewTime(table, "start_date")
	w.EndDate = field.NewTime(table, "end_date")
	w.Company = field.NewString(table, "company")
	w.Experience = field.NewString(table, "experience")
	w.OrganizationID = field.NewInt64(table, "organization_id")

	w.fillFieldMap()

	return w
}

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

func (w *workExperience) fillFieldMap() {
	w.fieldMap = make(map[string]field.Expr, 10)
	w.fieldMap["id"] = w.ID
	w.fieldMap["employee_id"] = w.EmployeeID
	w.fieldMap["created_at"] = w.CreatedAt
	w.fieldMap["updated_at"] = w.UpdatedAt
	w.fieldMap["deleted_at"] = w.DeletedAt
	w.fieldMap["start_date"] = w.StartDate
	w.fieldMap["end_date"] = w.EndDate
	w.fieldMap["company"] = w.Company
	w.fieldMap["experience"] = w.Experience
	w.fieldMap["organization_id"] = w.OrganizationID
}

func (w workExperience) clone(db *gorm.DB) workExperience {
	w.workExperienceDo.ReplaceConnPool(db.Statement.ConnPool)
	return w
}

func (w workExperience) replaceDB(db *gorm.DB) workExperience {
	w.workExperienceDo.ReplaceDB(db)
	return w
}

type workExperienceDo struct{ gen.DO }

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

func (w workExperienceDo) Debug() IWorkExperienceDo {
	return w.withDO(w.DO.Debug())
}

func (w workExperienceDo) WithContext(ctx context.Context) IWorkExperienceDo {
	return w.withDO(w.DO.WithContext(ctx))
}

func (w workExperienceDo) ReadDB() IWorkExperienceDo {
	return w.Clauses(dbresolver.Read)
}

func (w workExperienceDo) WriteDB() IWorkExperienceDo {
	return w.Clauses(dbresolver.Write)
}

func (w workExperienceDo) Session(config *gorm.Session) IWorkExperienceDo {
	return w.withDO(w.DO.Session(config))
}

func (w workExperienceDo) Clauses(conds ...clause.Expression) IWorkExperienceDo {
	return w.withDO(w.DO.Clauses(conds...))
}

func (w workExperienceDo) Returning(value interface{}, columns ...string) IWorkExperienceDo {
	return w.withDO(w.DO.Returning(value, columns...))
}

func (w workExperienceDo) Not(conds ...gen.Condition) IWorkExperienceDo {
	return w.withDO(w.DO.Not(conds...))
}

func (w workExperienceDo) Or(conds ...gen.Condition) IWorkExperienceDo {
	return w.withDO(w.DO.Or(conds...))
}

func (w workExperienceDo) Select(conds ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.Select(conds...))
}

func (w workExperienceDo) Where(conds ...gen.Condition) IWorkExperienceDo {
	return w.withDO(w.DO.Where(conds...))
}

func (w workExperienceDo) Order(conds ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.Order(conds...))
}

func (w workExperienceDo) Distinct(cols ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.Distinct(cols...))
}

func (w workExperienceDo) Omit(cols ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.Omit(cols...))
}

func (w workExperienceDo) Join(table schema.Tabler, on ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.Join(table, on...))
}

func (w workExperienceDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.LeftJoin(table, on...))
}

func (w workExperienceDo) RightJoin(table schema.Tabler, on ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.RightJoin(table, on...))
}

func (w workExperienceDo) Group(cols ...field.Expr) IWorkExperienceDo {
	return w.withDO(w.DO.Group(cols...))
}

func (w workExperienceDo) Having(conds ...gen.Condition) IWorkExperienceDo {
	return w.withDO(w.DO.Having(conds...))
}

func (w workExperienceDo) Limit(limit int) IWorkExperienceDo {
	return w.withDO(w.DO.Limit(limit))
}

func (w workExperienceDo) Offset(offset int) IWorkExperienceDo {
	return w.withDO(w.DO.Offset(offset))
}

func (w workExperienceDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWorkExperienceDo {
	return w.withDO(w.DO.Scopes(funcs...))
}

func (w workExperienceDo) Unscoped() IWorkExperienceDo {
	return w.withDO(w.DO.Unscoped())
}

func (w workExperienceDo) Create(values ...*model.WorkExperience) error {
	if len(values) == 0 {
		return nil
	}
	return w.DO.Create(values)
}

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

func (w workExperienceDo) First() (*model.WorkExperience, error) {
	if result, err := w.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.WorkExperience), nil
	}
}

func (w workExperienceDo) Take() (*model.WorkExperience, error) {
	if result, err := w.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.WorkExperience), nil
	}
}

func (w workExperienceDo) Last() (*model.WorkExperience, error) {
	if result, err := w.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.WorkExperience), nil
	}
}

func (w workExperienceDo) Find() ([]*model.WorkExperience, error) {
	result, err := w.DO.Find()
	return result.([]*model.WorkExperience), err
}

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

func (w workExperienceDo) Attrs(attrs ...field.AssignExpr) IWorkExperienceDo {
	return w.withDO(w.DO.Attrs(attrs...))
}

func (w workExperienceDo) Assign(attrs ...field.AssignExpr) IWorkExperienceDo {
	return w.withDO(w.DO.Assign(attrs...))
}

func (w workExperienceDo) Joins(fields ...field.RelationField) IWorkExperienceDo {
	for _, _f := range fields {
		w = *w.withDO(w.DO.Joins(_f))
	}
	return &w
}

func (w workExperienceDo) Preload(fields ...field.RelationField) IWorkExperienceDo {
	for _, _f := range fields {
		w = *w.withDO(w.DO.Preload(_f))
	}
	return &w
}

func (w workExperienceDo) FirstOrInit() (*model.WorkExperience, error) {
	if result, err := w.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.WorkExperience), nil
	}
}

func (w workExperienceDo) FirstOrCreate() (*model.WorkExperience, error) {
	if result, err := w.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.WorkExperience), nil
	}
}

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

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

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

func (w workExperienceDo) Scan(result interface{}) (err error) {
	return w.DO.Scan(result)
}

func (w workExperienceDo) Delete(models ...*model.WorkExperience) (result gen.ResultInfo, err error) {
	return w.DO.Delete(models)
}

func (w *workExperienceDo) withDO(do gen.Dao) *workExperienceDo {
	w.DO = *do.(*gen.DO)
	return w
}
