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

	_botsWithModel.botsWithModelDo.UseDB(db, opts...)
	_botsWithModel.botsWithModelDo.UseModel(&model.BotsWithModel{})

	tableName := _botsWithModel.botsWithModelDo.TableName()
	_botsWithModel.ALL = field.NewAsterisk(tableName)
	_botsWithModel.ID = field.NewInt64(tableName, "id")
	_botsWithModel.BotID = field.NewInt64(tableName, "bot_id")
	_botsWithModel.ModelType = field.NewString(tableName, "model_type")
	_botsWithModel.ModelName = field.NewString(tableName, "model_name")
	_botsWithModel.Temperature = field.NewFloat64(tableName, "temperature")
	_botsWithModel.CreatedAt = field.NewTime(tableName, "created_at")
	_botsWithModel.UpdatedAt = field.NewTime(tableName, "updated_at")

	_botsWithModel.fillFieldMap()

	return _botsWithModel
}

type botsWithModel struct {
	botsWithModelDo botsWithModelDo

	ALL         field.Asterisk
	ID          field.Int64   // 机器人初始设置ID
	BotID       field.Int64   // 机器人ID 关联 bots.id
	ModelType   field.String  // 模型类型 openai/gemini
	ModelName   field.String  // 模型名称
	Temperature field.Float64 // 温度
	CreatedAt   field.Time    // 创建时间
	UpdatedAt   field.Time    // 更新时间

	fieldMap map[string]field.Expr
}

func (b botsWithModel) Table(newTableName string) *botsWithModel {
	b.botsWithModelDo.UseTable(newTableName)
	return b.updateTableName(newTableName)
}

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

func (b *botsWithModel) updateTableName(table string) *botsWithModel {
	b.ALL = field.NewAsterisk(table)
	b.ID = field.NewInt64(table, "id")
	b.BotID = field.NewInt64(table, "bot_id")
	b.ModelType = field.NewString(table, "model_type")
	b.ModelName = field.NewString(table, "model_name")
	b.Temperature = field.NewFloat64(table, "temperature")
	b.CreatedAt = field.NewTime(table, "created_at")
	b.UpdatedAt = field.NewTime(table, "updated_at")

	b.fillFieldMap()

	return b
}

func (b *botsWithModel) WithContext(ctx context.Context) *botsWithModelDo {
	return b.botsWithModelDo.WithContext(ctx)
}

func (b botsWithModel) TableName() string { return b.botsWithModelDo.TableName() }

func (b botsWithModel) Alias() string { return b.botsWithModelDo.Alias() }

func (b botsWithModel) Columns(cols ...field.Expr) gen.Columns {
	return b.botsWithModelDo.Columns(cols...)
}

func (b *botsWithModel) 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 *botsWithModel) fillFieldMap() {
	b.fieldMap = make(map[string]field.Expr, 7)
	b.fieldMap["id"] = b.ID
	b.fieldMap["bot_id"] = b.BotID
	b.fieldMap["model_type"] = b.ModelType
	b.fieldMap["model_name"] = b.ModelName
	b.fieldMap["temperature"] = b.Temperature
	b.fieldMap["created_at"] = b.CreatedAt
	b.fieldMap["updated_at"] = b.UpdatedAt
}

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

func (b botsWithModel) replaceDB(db *gorm.DB) botsWithModel {
	b.botsWithModelDo.ReplaceDB(db)
	return b
}

type botsWithModelDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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