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

	_wxCard.wxCardDo.UseDB(db, opts...)
	_wxCard.wxCardDo.UseModel(&model.WxCard{})

	tableName := _wxCard.wxCardDo.TableName()
	_wxCard.ALL = field.NewAsterisk(tableName)
	_wxCard.ID = field.NewInt64(tableName, "id")
	_wxCard.CreatedAt = field.NewTime(tableName, "created_at")
	_wxCard.UpdatedAt = field.NewTime(tableName, "updated_at")
	_wxCard.DeletedAt = field.NewField(tableName, "deleted_at")
	_wxCard.UserID = field.NewInt64(tableName, "user_id")
	_wxCard.WxUserID = field.NewInt64(tableName, "wx_user_id")
	_wxCard.Avatar = field.NewString(tableName, "avatar")
	_wxCard.Logo = field.NewString(tableName, "logo")
	_wxCard.Name = field.NewString(tableName, "name")
	_wxCard.Company = field.NewString(tableName, "company")
	_wxCard.Address = field.NewString(tableName, "address")
	_wxCard.Phone = field.NewString(tableName, "phone")
	_wxCard.OfficialAccount = field.NewString(tableName, "official_account")
	_wxCard.WechatAccount = field.NewString(tableName, "wechat_account")
	_wxCard.Email = field.NewString(tableName, "email")
	_wxCard.APIBase = field.NewString(tableName, "api_base")
	_wxCard.APIKey = field.NewString(tableName, "api_key")
	_wxCard.AiInfo = field.NewString(tableName, "ai_info")
	_wxCard.Intro = field.NewString(tableName, "intro")

	_wxCard.fillFieldMap()

	return _wxCard
}

// wxCard 名片表
type wxCard struct {
	wxCardDo

	ALL             field.Asterisk
	ID              field.Int64
	CreatedAt       field.Time   // Create Time | 创建日期
	UpdatedAt       field.Time   // Update Time | 修改日期
	DeletedAt       field.Field  // Delete Time | 删除日期
	UserID          field.Int64  // use表ID
	WxUserID        field.Int64  // wx表ID
	Avatar          field.String // 头像
	Logo            field.String // Logo
	Name            field.String // 名称
	Company         field.String // 公司
	Address         field.String // 地址
	Phone           field.String // 手机号
	OfficialAccount field.String // 公众号
	WechatAccount   field.String // 微信号
	Email           field.String // 邮箱
	APIBase         field.String // fastgpt-base
	APIKey          field.String // fastgpt-key
	AiInfo          field.String // AI信息
	Intro           field.String // 简介

	fieldMap map[string]field.Expr
}

func (w wxCard) Table(newTableName string) *wxCard {
	w.wxCardDo.UseTable(newTableName)
	return w.updateTableName(newTableName)
}

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

func (w *wxCard) updateTableName(table string) *wxCard {
	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.UserID = field.NewInt64(table, "user_id")
	w.WxUserID = field.NewInt64(table, "wx_user_id")
	w.Avatar = field.NewString(table, "avatar")
	w.Logo = field.NewString(table, "logo")
	w.Name = field.NewString(table, "name")
	w.Company = field.NewString(table, "company")
	w.Address = field.NewString(table, "address")
	w.Phone = field.NewString(table, "phone")
	w.OfficialAccount = field.NewString(table, "official_account")
	w.WechatAccount = field.NewString(table, "wechat_account")
	w.Email = field.NewString(table, "email")
	w.APIBase = field.NewString(table, "api_base")
	w.APIKey = field.NewString(table, "api_key")
	w.AiInfo = field.NewString(table, "ai_info")
	w.Intro = field.NewString(table, "intro")

	w.fillFieldMap()

	return w
}

func (w *wxCard) 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 *wxCard) fillFieldMap() {
	w.fieldMap = make(map[string]field.Expr, 19)
	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["user_id"] = w.UserID
	w.fieldMap["wx_user_id"] = w.WxUserID
	w.fieldMap["avatar"] = w.Avatar
	w.fieldMap["logo"] = w.Logo
	w.fieldMap["name"] = w.Name
	w.fieldMap["company"] = w.Company
	w.fieldMap["address"] = w.Address
	w.fieldMap["phone"] = w.Phone
	w.fieldMap["official_account"] = w.OfficialAccount
	w.fieldMap["wechat_account"] = w.WechatAccount
	w.fieldMap["email"] = w.Email
	w.fieldMap["api_base"] = w.APIBase
	w.fieldMap["api_key"] = w.APIKey
	w.fieldMap["ai_info"] = w.AiInfo
	w.fieldMap["intro"] = w.Intro
}

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

func (w wxCard) replaceDB(db *gorm.DB) wxCard {
	w.wxCardDo.ReplaceDB(db)
	return w
}

type wxCardDo struct{ gen.DO }

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

func (w wxCardDo) Debug() IWxCardDo {
	return w.withDO(w.DO.Debug())
}

func (w wxCardDo) WithContext(ctx context.Context) IWxCardDo {
	return w.withDO(w.DO.WithContext(ctx))
}

func (w wxCardDo) ReadDB() IWxCardDo {
	return w.Clauses(dbresolver.Read)
}

func (w wxCardDo) WriteDB() IWxCardDo {
	return w.Clauses(dbresolver.Write)
}

func (w wxCardDo) Session(config *gorm.Session) IWxCardDo {
	return w.withDO(w.DO.Session(config))
}

func (w wxCardDo) Clauses(conds ...clause.Expression) IWxCardDo {
	return w.withDO(w.DO.Clauses(conds...))
}

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

func (w wxCardDo) Not(conds ...gen.Condition) IWxCardDo {
	return w.withDO(w.DO.Not(conds...))
}

func (w wxCardDo) Or(conds ...gen.Condition) IWxCardDo {
	return w.withDO(w.DO.Or(conds...))
}

func (w wxCardDo) Select(conds ...field.Expr) IWxCardDo {
	return w.withDO(w.DO.Select(conds...))
}

func (w wxCardDo) Where(conds ...gen.Condition) IWxCardDo {
	return w.withDO(w.DO.Where(conds...))
}

func (w wxCardDo) Order(conds ...field.Expr) IWxCardDo {
	return w.withDO(w.DO.Order(conds...))
}

func (w wxCardDo) Distinct(cols ...field.Expr) IWxCardDo {
	return w.withDO(w.DO.Distinct(cols...))
}

func (w wxCardDo) Omit(cols ...field.Expr) IWxCardDo {
	return w.withDO(w.DO.Omit(cols...))
}

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

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

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

func (w wxCardDo) Group(cols ...field.Expr) IWxCardDo {
	return w.withDO(w.DO.Group(cols...))
}

func (w wxCardDo) Having(conds ...gen.Condition) IWxCardDo {
	return w.withDO(w.DO.Having(conds...))
}

func (w wxCardDo) Limit(limit int) IWxCardDo {
	return w.withDO(w.DO.Limit(limit))
}

func (w wxCardDo) Offset(offset int) IWxCardDo {
	return w.withDO(w.DO.Offset(offset))
}

func (w wxCardDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWxCardDo {
	return w.withDO(w.DO.Scopes(funcs...))
}

func (w wxCardDo) Unscoped() IWxCardDo {
	return w.withDO(w.DO.Unscoped())
}

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

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

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

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

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

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

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

func (w wxCardDo) Attrs(attrs ...field.AssignExpr) IWxCardDo {
	return w.withDO(w.DO.Attrs(attrs...))
}

func (w wxCardDo) Assign(attrs ...field.AssignExpr) IWxCardDo {
	return w.withDO(w.DO.Assign(attrs...))
}

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

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

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

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

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

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

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