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

	_wxCardUser.wxCardUserDo.UseDB(db, opts...)
	_wxCardUser.wxCardUserDo.UseModel(&model.WxCardUser{})

	tableName := _wxCardUser.wxCardUserDo.TableName()
	_wxCardUser.ALL = field.NewAsterisk(tableName)
	_wxCardUser.ID = field.NewInt64(tableName, "id")
	_wxCardUser.CreatedAt = field.NewTime(tableName, "created_at")
	_wxCardUser.UpdatedAt = field.NewTime(tableName, "updated_at")
	_wxCardUser.DeletedAt = field.NewField(tableName, "deleted_at")
	_wxCardUser.Wxid = field.NewString(tableName, "wxid")
	_wxCardUser.Account = field.NewString(tableName, "account")
	_wxCardUser.Nickname = field.NewString(tableName, "nickname")
	_wxCardUser.Remark = field.NewString(tableName, "remark")
	_wxCardUser.Avatar = field.NewString(tableName, "avatar")
	_wxCardUser.Phone = field.NewString(tableName, "phone")
	_wxCardUser.OpenID = field.NewString(tableName, "open_id")
	_wxCardUser.UnionID = field.NewString(tableName, "union_id")
	_wxCardUser.SessionKey = field.NewString(tableName, "session_key")
	_wxCardUser.IsVip = field.NewInt64(tableName, "is_vip")

	_wxCardUser.fillFieldMap()

	return _wxCardUser
}

// wxCardUser 微信用户表
type wxCardUser struct {
	wxCardUserDo

	ALL        field.Asterisk
	ID         field.Int64
	CreatedAt  field.Time   // Create Time | 创建日期
	UpdatedAt  field.Time   // Update Time | 修改日期
	DeletedAt  field.Field  // Delete Time | 删除日期
	Wxid       field.String // 微信id
	Account    field.String // 微信账号
	Nickname   field.String // 微信昵称
	Remark     field.String // 备注名
	Avatar     field.String // 头像
	Phone      field.String // 手机号
	OpenID     field.String // OpenId
	UnionID    field.String // UnionId
	SessionKey field.String // SessionKey
	IsVip      field.Int64  // 是否VIP：0-否 1-是

	fieldMap map[string]field.Expr
}

func (w wxCardUser) Table(newTableName string) *wxCardUser {
	w.wxCardUserDo.UseTable(newTableName)
	return w.updateTableName(newTableName)
}

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

func (w *wxCardUser) updateTableName(table string) *wxCardUser {
	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.DeletedAt = field.NewField(table, "deleted_at")
	w.Wxid = field.NewString(table, "wxid")
	w.Account = field.NewString(table, "account")
	w.Nickname = field.NewString(table, "nickname")
	w.Remark = field.NewString(table, "remark")
	w.Avatar = field.NewString(table, "avatar")
	w.Phone = field.NewString(table, "phone")
	w.OpenID = field.NewString(table, "open_id")
	w.UnionID = field.NewString(table, "union_id")
	w.SessionKey = field.NewString(table, "session_key")
	w.IsVip = field.NewInt64(table, "is_vip")

	w.fillFieldMap()

	return w
}

func (w *wxCardUser) 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 *wxCardUser) fillFieldMap() {
	w.fieldMap = make(map[string]field.Expr, 14)
	w.fieldMap["id"] = w.ID
	w.fieldMap["created_at"] = w.CreatedAt
	w.fieldMap["updated_at"] = w.UpdatedAt
	w.fieldMap["deleted_at"] = w.DeletedAt
	w.fieldMap["wxid"] = w.Wxid
	w.fieldMap["account"] = w.Account
	w.fieldMap["nickname"] = w.Nickname
	w.fieldMap["remark"] = w.Remark
	w.fieldMap["avatar"] = w.Avatar
	w.fieldMap["phone"] = w.Phone
	w.fieldMap["open_id"] = w.OpenID
	w.fieldMap["union_id"] = w.UnionID
	w.fieldMap["session_key"] = w.SessionKey
	w.fieldMap["is_vip"] = w.IsVip
}

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

func (w wxCardUser) replaceDB(db *gorm.DB) wxCardUser {
	w.wxCardUserDo.ReplaceDB(db)
	return w
}

type wxCardUserDo struct{ gen.DO }

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

func (w wxCardUserDo) Debug() IWxCardUserDo {
	return w.withDO(w.DO.Debug())
}

func (w wxCardUserDo) WithContext(ctx context.Context) IWxCardUserDo {
	return w.withDO(w.DO.WithContext(ctx))
}

func (w wxCardUserDo) ReadDB() IWxCardUserDo {
	return w.Clauses(dbresolver.Read)
}

func (w wxCardUserDo) WriteDB() IWxCardUserDo {
	return w.Clauses(dbresolver.Write)
}

func (w wxCardUserDo) Session(config *gorm.Session) IWxCardUserDo {
	return w.withDO(w.DO.Session(config))
}

func (w wxCardUserDo) Clauses(conds ...clause.Expression) IWxCardUserDo {
	return w.withDO(w.DO.Clauses(conds...))
}

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

func (w wxCardUserDo) Not(conds ...gen.Condition) IWxCardUserDo {
	return w.withDO(w.DO.Not(conds...))
}

func (w wxCardUserDo) Or(conds ...gen.Condition) IWxCardUserDo {
	return w.withDO(w.DO.Or(conds...))
}

func (w wxCardUserDo) Select(conds ...field.Expr) IWxCardUserDo {
	return w.withDO(w.DO.Select(conds...))
}

func (w wxCardUserDo) Where(conds ...gen.Condition) IWxCardUserDo {
	return w.withDO(w.DO.Where(conds...))
}

func (w wxCardUserDo) Order(conds ...field.Expr) IWxCardUserDo {
	return w.withDO(w.DO.Order(conds...))
}

func (w wxCardUserDo) Distinct(cols ...field.Expr) IWxCardUserDo {
	return w.withDO(w.DO.Distinct(cols...))
}

func (w wxCardUserDo) Omit(cols ...field.Expr) IWxCardUserDo {
	return w.withDO(w.DO.Omit(cols...))
}

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

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

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

func (w wxCardUserDo) Group(cols ...field.Expr) IWxCardUserDo {
	return w.withDO(w.DO.Group(cols...))
}

func (w wxCardUserDo) Having(conds ...gen.Condition) IWxCardUserDo {
	return w.withDO(w.DO.Having(conds...))
}

func (w wxCardUserDo) Limit(limit int) IWxCardUserDo {
	return w.withDO(w.DO.Limit(limit))
}

func (w wxCardUserDo) Offset(offset int) IWxCardUserDo {
	return w.withDO(w.DO.Offset(offset))
}

func (w wxCardUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWxCardUserDo {
	return w.withDO(w.DO.Scopes(funcs...))
}

func (w wxCardUserDo) Unscoped() IWxCardUserDo {
	return w.withDO(w.DO.Unscoped())
}

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

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

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

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

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

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

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

func (w wxCardUserDo) Attrs(attrs ...field.AssignExpr) IWxCardUserDo {
	return w.withDO(w.DO.Attrs(attrs...))
}

func (w wxCardUserDo) Assign(attrs ...field.AssignExpr) IWxCardUserDo {
	return w.withDO(w.DO.Assign(attrs...))
}

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

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

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

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

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

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

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