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

	_wpChatroomMember.wpChatroomMemberDo.UseDB(db, opts...)
	_wpChatroomMember.wpChatroomMemberDo.UseModel(&model.WpChatroomMember{})

	tableName := _wpChatroomMember.wpChatroomMemberDo.TableName()
	_wpChatroomMember.ALL = field.NewAsterisk(tableName)
	_wpChatroomMember.ID = field.NewInt64(tableName, "id")
	_wpChatroomMember.CreatedAt = field.NewTime(tableName, "created_at")
	_wpChatroomMember.UpdatedAt = field.NewTime(tableName, "updated_at")
	_wpChatroomMember.Status = field.NewInt64(tableName, "status")
	_wpChatroomMember.DeletedAt = field.NewField(tableName, "deleted_at")
	_wpChatroomMember.WxWxid = field.NewString(tableName, "wx_wxid")
	_wpChatroomMember.Wxid = field.NewString(tableName, "wxid")
	_wpChatroomMember.Nickname = field.NewString(tableName, "nickname")
	_wpChatroomMember.Avatar = field.NewString(tableName, "avatar")

	_wpChatroomMember.fillFieldMap()

	return _wpChatroomMember
}

type wpChatroomMember struct {
	wpChatroomMemberDo

	ALL       field.Asterisk
	ID        field.Int64
	CreatedAt field.Time   // Create Time | 创建日期
	UpdatedAt field.Time   // Update Time | 修改日期
	Status    field.Int64  // Status 1: normal 2: ban | 状态 1 正常 2 禁用
	DeletedAt field.Field  // Delete Time | 删除日期
	WxWxid    field.String // 属主微信id
	Wxid      field.String // 微信id
	Nickname  field.String // 微信昵称 群备注名称
	Avatar    field.String // 头像

	fieldMap map[string]field.Expr
}

func (w wpChatroomMember) Table(newTableName string) *wpChatroomMember {
	w.wpChatroomMemberDo.UseTable(newTableName)
	return w.updateTableName(newTableName)
}

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

func (w *wpChatroomMember) updateTableName(table string) *wpChatroomMember {
	w.ALL = field.NewAsterisk(table)
	w.ID = field.NewInt64(table, "id")
	w.CreatedAt = field.NewTime(table, "created_at")
	w.UpdatedAt = field.NewTime(table, "updated_at")
	w.Status = field.NewInt64(table, "status")
	w.DeletedAt = field.NewField(table, "deleted_at")
	w.WxWxid = field.NewString(table, "wx_wxid")
	w.Wxid = field.NewString(table, "wxid")
	w.Nickname = field.NewString(table, "nickname")
	w.Avatar = field.NewString(table, "avatar")

	w.fillFieldMap()

	return w
}

func (w *wpChatroomMember) 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 *wpChatroomMember) fillFieldMap() {
	w.fieldMap = make(map[string]field.Expr, 9)
	w.fieldMap["id"] = w.ID
	w.fieldMap["created_at"] = w.CreatedAt
	w.fieldMap["updated_at"] = w.UpdatedAt
	w.fieldMap["status"] = w.Status
	w.fieldMap["deleted_at"] = w.DeletedAt
	w.fieldMap["wx_wxid"] = w.WxWxid
	w.fieldMap["wxid"] = w.Wxid
	w.fieldMap["nickname"] = w.Nickname
	w.fieldMap["avatar"] = w.Avatar
}

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

func (w wpChatroomMember) replaceDB(db *gorm.DB) wpChatroomMember {
	w.wpChatroomMemberDo.ReplaceDB(db)
	return w
}

type wpChatroomMemberDo struct{ gen.DO }

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

func (w wpChatroomMemberDo) Debug() IWpChatroomMemberDo {
	return w.withDO(w.DO.Debug())
}

func (w wpChatroomMemberDo) WithContext(ctx context.Context) IWpChatroomMemberDo {
	return w.withDO(w.DO.WithContext(ctx))
}

func (w wpChatroomMemberDo) ReadDB() IWpChatroomMemberDo {
	return w.Clauses(dbresolver.Read)
}

func (w wpChatroomMemberDo) WriteDB() IWpChatroomMemberDo {
	return w.Clauses(dbresolver.Write)
}

func (w wpChatroomMemberDo) Session(config *gorm.Session) IWpChatroomMemberDo {
	return w.withDO(w.DO.Session(config))
}

func (w wpChatroomMemberDo) Clauses(conds ...clause.Expression) IWpChatroomMemberDo {
	return w.withDO(w.DO.Clauses(conds...))
}

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

func (w wpChatroomMemberDo) Not(conds ...gen.Condition) IWpChatroomMemberDo {
	return w.withDO(w.DO.Not(conds...))
}

func (w wpChatroomMemberDo) Or(conds ...gen.Condition) IWpChatroomMemberDo {
	return w.withDO(w.DO.Or(conds...))
}

func (w wpChatroomMemberDo) Select(conds ...field.Expr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Select(conds...))
}

func (w wpChatroomMemberDo) Where(conds ...gen.Condition) IWpChatroomMemberDo {
	return w.withDO(w.DO.Where(conds...))
}

func (w wpChatroomMemberDo) Order(conds ...field.Expr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Order(conds...))
}

func (w wpChatroomMemberDo) Distinct(cols ...field.Expr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Distinct(cols...))
}

func (w wpChatroomMemberDo) Omit(cols ...field.Expr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Omit(cols...))
}

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

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

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

func (w wpChatroomMemberDo) Group(cols ...field.Expr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Group(cols...))
}

func (w wpChatroomMemberDo) Having(conds ...gen.Condition) IWpChatroomMemberDo {
	return w.withDO(w.DO.Having(conds...))
}

func (w wpChatroomMemberDo) Limit(limit int) IWpChatroomMemberDo {
	return w.withDO(w.DO.Limit(limit))
}

func (w wpChatroomMemberDo) Offset(offset int) IWpChatroomMemberDo {
	return w.withDO(w.DO.Offset(offset))
}

func (w wpChatroomMemberDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWpChatroomMemberDo {
	return w.withDO(w.DO.Scopes(funcs...))
}

func (w wpChatroomMemberDo) Unscoped() IWpChatroomMemberDo {
	return w.withDO(w.DO.Unscoped())
}

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

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

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

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

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

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

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

func (w wpChatroomMemberDo) Attrs(attrs ...field.AssignExpr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Attrs(attrs...))
}

func (w wpChatroomMemberDo) Assign(attrs ...field.AssignExpr) IWpChatroomMemberDo {
	return w.withDO(w.DO.Assign(attrs...))
}

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

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

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

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

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

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

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