// 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 dao

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"chat/service/chat/model"
)

func newBotsWithCustom(db *gorm.DB, opts ...gen.DOOption) botsWithCustom {
	_botsWithCustom := botsWithCustom{}

	_botsWithCustom.botsWithCustomDo.UseDB(db, opts...)
	_botsWithCustom.botsWithCustomDo.UseModel(&model.BotsWithCustom{})

	tableName := _botsWithCustom.botsWithCustomDo.TableName()
	_botsWithCustom.ALL = field.NewAsterisk(tableName)
	_botsWithCustom.ID = field.NewInt64(tableName, "id")
	_botsWithCustom.BotID = field.NewInt64(tableName, "bot_id")
	_botsWithCustom.OpenKfID = field.NewString(tableName, "open_kf_id")
	_botsWithCustom.CreatedAt = field.NewTime(tableName, "created_at")
	_botsWithCustom.UpdatedAt = field.NewTime(tableName, "updated_at")

	_botsWithCustom.fillFieldMap()

	return _botsWithCustom
}

type botsWithCustom struct {
	botsWithCustomDo botsWithCustomDo

	ALL       field.Asterisk
	ID        field.Int64  // 机器人初始设置ID
	BotID     field.Int64  // 机器人ID 关联 bots.id
	OpenKfID  field.String // 客服id 关联企业微信 客服ID
	CreatedAt field.Time   // 创建时间
	UpdatedAt field.Time   // 更新时间

	fieldMap map[string]field.Expr
}

func (b botsWithCustom) Table(newTableName string) *botsWithCustom {
	b.botsWithCustomDo.UseTable(newTableName)
	return b.updateTableName(newTableName)
}

func (b botsWithCustom) As(alias string) *botsWithCustom {
	b.botsWithCustomDo.DO = *(b.botsWithCustomDo.As(alias).(*gen.DO))
	return b.updateTableName(alias)
}

func (b *botsWithCustom) updateTableName(table string) *botsWithCustom {
	b.ALL = field.NewAsterisk(table)
	b.ID = field.NewInt64(table, "id")
	b.BotID = field.NewInt64(table, "bot_id")
	b.OpenKfID = field.NewString(table, "open_kf_id")
	b.CreatedAt = field.NewTime(table, "created_at")
	b.UpdatedAt = field.NewTime(table, "updated_at")

	b.fillFieldMap()

	return b
}

func (b *botsWithCustom) WithContext(ctx context.Context) *botsWithCustomDo {
	return b.botsWithCustomDo.WithContext(ctx)
}

func (b botsWithCustom) TableName() string { return b.botsWithCustomDo.TableName() }

func (b botsWithCustom) Alias() string { return b.botsWithCustomDo.Alias() }

func (b botsWithCustom) Columns(cols ...field.Expr) gen.Columns {
	return b.botsWithCustomDo.Columns(cols...)
}

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

func (b *botsWithCustom) fillFieldMap() {
	b.fieldMap = make(map[string]field.Expr, 5)
	b.fieldMap["id"] = b.ID
	b.fieldMap["bot_id"] = b.BotID
	b.fieldMap["open_kf_id"] = b.OpenKfID
	b.fieldMap["created_at"] = b.CreatedAt
	b.fieldMap["updated_at"] = b.UpdatedAt
}

func (b botsWithCustom) clone(db *gorm.DB) botsWithCustom {
	b.botsWithCustomDo.ReplaceConnPool(db.Statement.ConnPool)
	return b
}

func (b botsWithCustom) replaceDB(db *gorm.DB) botsWithCustom {
	b.botsWithCustomDo.ReplaceDB(db)
	return b
}

type botsWithCustomDo struct{ gen.DO }

func (b botsWithCustomDo) Debug() *botsWithCustomDo {
	return b.withDO(b.DO.Debug())
}

func (b botsWithCustomDo) WithContext(ctx context.Context) *botsWithCustomDo {
	return b.withDO(b.DO.WithContext(ctx))
}

func (b botsWithCustomDo) ReadDB() *botsWithCustomDo {
	return b.Clauses(dbresolver.Read)
}

func (b botsWithCustomDo) WriteDB() *botsWithCustomDo {
	return b.Clauses(dbresolver.Write)
}

func (b botsWithCustomDo) Session(config *gorm.Session) *botsWithCustomDo {
	return b.withDO(b.DO.Session(config))
}

func (b botsWithCustomDo) Clauses(conds ...clause.Expression) *botsWithCustomDo {
	return b.withDO(b.DO.Clauses(conds...))
}

func (b botsWithCustomDo) Returning(value interface{}, columns ...string) *botsWithCustomDo {
	return b.withDO(b.DO.Returning(value, columns...))
}

func (b botsWithCustomDo) Not(conds ...gen.Condition) *botsWithCustomDo {
	return b.withDO(b.DO.Not(conds...))
}

func (b botsWithCustomDo) Or(conds ...gen.Condition) *botsWithCustomDo {
	return b.withDO(b.DO.Or(conds...))
}

func (b botsWithCustomDo) Select(conds ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.Select(conds...))
}

func (b botsWithCustomDo) Where(conds ...gen.Condition) *botsWithCustomDo {
	return b.withDO(b.DO.Where(conds...))
}

func (b botsWithCustomDo) Order(conds ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.Order(conds...))
}

func (b botsWithCustomDo) Distinct(cols ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.Distinct(cols...))
}

func (b botsWithCustomDo) Omit(cols ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.Omit(cols...))
}

func (b botsWithCustomDo) Join(table schema.Tabler, on ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.Join(table, on...))
}

func (b botsWithCustomDo) LeftJoin(table schema.Tabler, on ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.LeftJoin(table, on...))
}

func (b botsWithCustomDo) RightJoin(table schema.Tabler, on ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.RightJoin(table, on...))
}

func (b botsWithCustomDo) Group(cols ...field.Expr) *botsWithCustomDo {
	return b.withDO(b.DO.Group(cols...))
}

func (b botsWithCustomDo) Having(conds ...gen.Condition) *botsWithCustomDo {
	return b.withDO(b.DO.Having(conds...))
}

func (b botsWithCustomDo) Limit(limit int) *botsWithCustomDo {
	return b.withDO(b.DO.Limit(limit))
}

func (b botsWithCustomDo) Offset(offset int) *botsWithCustomDo {
	return b.withDO(b.DO.Offset(offset))
}

func (b botsWithCustomDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *botsWithCustomDo {
	return b.withDO(b.DO.Scopes(funcs...))
}

func (b botsWithCustomDo) Unscoped() *botsWithCustomDo {
	return b.withDO(b.DO.Unscoped())
}

func (b botsWithCustomDo) Create(values ...*model.BotsWithCustom) error {
	if len(values) == 0 {
		return nil
	}
	return b.DO.Create(values)
}

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

func (b botsWithCustomDo) First() (*model.BotsWithCustom, error) {
	if result, err := b.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.BotsWithCustom), nil
	}
}

func (b botsWithCustomDo) Take() (*model.BotsWithCustom, error) {
	if result, err := b.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.BotsWithCustom), nil
	}
}

func (b botsWithCustomDo) Last() (*model.BotsWithCustom, error) {
	if result, err := b.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.BotsWithCustom), nil
	}
}

func (b botsWithCustomDo) Find() ([]*model.BotsWithCustom, error) {
	result, err := b.DO.Find()
	return result.([]*model.BotsWithCustom), err
}

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

func (b botsWithCustomDo) Attrs(attrs ...field.AssignExpr) *botsWithCustomDo {
	return b.withDO(b.DO.Attrs(attrs...))
}

func (b botsWithCustomDo) Assign(attrs ...field.AssignExpr) *botsWithCustomDo {
	return b.withDO(b.DO.Assign(attrs...))
}

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

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

func (b botsWithCustomDo) FirstOrInit() (*model.BotsWithCustom, error) {
	if result, err := b.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.BotsWithCustom), nil
	}
}

func (b botsWithCustomDo) FirstOrCreate() (*model.BotsWithCustom, error) {
	if result, err := b.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.BotsWithCustom), nil
	}
}

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

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

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

func (b botsWithCustomDo) Scan(result interface{}) (err error) {
	return b.DO.Scan(result)
}

func (b botsWithCustomDo) Delete(models ...*model.BotsWithCustom) (result gen.ResultInfo, err error) {
	return b.DO.Delete(models)
}

func (b *botsWithCustomDo) withDO(do gen.Dao) *botsWithCustomDo {
	b.DO = *do.(*gen.DO)
	return b
}
