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

	"mini-chat/internal/repository/mysql/model"
)

func newAppKeywordReply(db *gorm.DB, opts ...gen.DOOption) appKeywordReply {
	_appKeywordReply := appKeywordReply{}

	_appKeywordReply.appKeywordReplyDo.UseDB(db, opts...)
	_appKeywordReply.appKeywordReplyDo.UseModel(&model.AppKeywordReply{})

	tableName := _appKeywordReply.appKeywordReplyDo.TableName()
	_appKeywordReply.ALL = field.NewAsterisk(tableName)
	_appKeywordReply.ID = field.NewInt32(tableName, "id")
	_appKeywordReply.AppID = field.NewString(tableName, "app_id")
	_appKeywordReply.KeywordID = field.NewInt32(tableName, "keyword_id")
	_appKeywordReply.IntervalSeconds = field.NewInt32(tableName, "interval_seconds")
	_appKeywordReply.Type = field.NewInt32(tableName, "type")
	_appKeywordReply.Content = field.NewString(tableName, "content")
	_appKeywordReply.CreatedUser = field.NewString(tableName, "created_user")
	_appKeywordReply.CreatedAt = field.NewTime(tableName, "created_at")
	_appKeywordReply.UpdatedUser = field.NewString(tableName, "updated_user")
	_appKeywordReply.UpdatedAt = field.NewTime(tableName, "updated_at")

	_appKeywordReply.fillFieldMap()

	return _appKeywordReply
}

// appKeywordReply 关键字回复表
type appKeywordReply struct {
	appKeywordReplyDo

	ALL             field.Asterisk
	ID              field.Int32  // 主键ID
	AppID           field.String // 小程序ID
	KeywordID       field.Int32  // 关联 app_keyword 表的ID
	IntervalSeconds field.Int32  // 时间间隔，单位为秒
	Type            field.Int32  // 类型(1:文本 2:图片 3:语音条 4:视频 5=小程序 6=地理位置 7=链接 8=GIF图 9=名片 10=文件 11=转人工)
	Content         field.String // 内容
	CreatedUser     field.String // 创建人
	CreatedAt       field.Time   // 创建时间
	UpdatedUser     field.String // 更新人
	UpdatedAt       field.Time   // 更新时间

	fieldMap map[string]field.Expr
}

func (a appKeywordReply) Table(newTableName string) *appKeywordReply {
	a.appKeywordReplyDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a appKeywordReply) As(alias string) *appKeywordReply {
	a.appKeywordReplyDo.DO = *(a.appKeywordReplyDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *appKeywordReply) updateTableName(table string) *appKeywordReply {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt32(table, "id")
	a.AppID = field.NewString(table, "app_id")
	a.KeywordID = field.NewInt32(table, "keyword_id")
	a.IntervalSeconds = field.NewInt32(table, "interval_seconds")
	a.Type = field.NewInt32(table, "type")
	a.Content = field.NewString(table, "content")
	a.CreatedUser = field.NewString(table, "created_user")
	a.CreatedAt = field.NewTime(table, "created_at")
	a.UpdatedUser = field.NewString(table, "updated_user")
	a.UpdatedAt = field.NewTime(table, "updated_at")

	a.fillFieldMap()

	return a
}

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

func (a *appKeywordReply) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 10)
	a.fieldMap["id"] = a.ID
	a.fieldMap["app_id"] = a.AppID
	a.fieldMap["keyword_id"] = a.KeywordID
	a.fieldMap["interval_seconds"] = a.IntervalSeconds
	a.fieldMap["type"] = a.Type
	a.fieldMap["content"] = a.Content
	a.fieldMap["created_user"] = a.CreatedUser
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["updated_user"] = a.UpdatedUser
	a.fieldMap["updated_at"] = a.UpdatedAt
}

func (a appKeywordReply) clone(db *gorm.DB) appKeywordReply {
	a.appKeywordReplyDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a appKeywordReply) replaceDB(db *gorm.DB) appKeywordReply {
	a.appKeywordReplyDo.ReplaceDB(db)
	return a
}

type appKeywordReplyDo struct{ gen.DO }

func (a appKeywordReplyDo) Debug() *appKeywordReplyDo {
	return a.withDO(a.DO.Debug())
}

func (a appKeywordReplyDo) WithContext(ctx context.Context) *appKeywordReplyDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a appKeywordReplyDo) ReadDB() *appKeywordReplyDo {
	return a.Clauses(dbresolver.Read)
}

func (a appKeywordReplyDo) WriteDB() *appKeywordReplyDo {
	return a.Clauses(dbresolver.Write)
}

func (a appKeywordReplyDo) Session(config *gorm.Session) *appKeywordReplyDo {
	return a.withDO(a.DO.Session(config))
}

func (a appKeywordReplyDo) Clauses(conds ...clause.Expression) *appKeywordReplyDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a appKeywordReplyDo) Not(conds ...gen.Condition) *appKeywordReplyDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a appKeywordReplyDo) Or(conds ...gen.Condition) *appKeywordReplyDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a appKeywordReplyDo) Select(conds ...field.Expr) *appKeywordReplyDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a appKeywordReplyDo) Where(conds ...gen.Condition) *appKeywordReplyDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a appKeywordReplyDo) Order(conds ...field.Expr) *appKeywordReplyDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a appKeywordReplyDo) Distinct(cols ...field.Expr) *appKeywordReplyDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a appKeywordReplyDo) Omit(cols ...field.Expr) *appKeywordReplyDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a appKeywordReplyDo) Group(cols ...field.Expr) *appKeywordReplyDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a appKeywordReplyDo) Having(conds ...gen.Condition) *appKeywordReplyDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a appKeywordReplyDo) Limit(limit int) *appKeywordReplyDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a appKeywordReplyDo) Offset(offset int) *appKeywordReplyDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a appKeywordReplyDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *appKeywordReplyDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a appKeywordReplyDo) Unscoped() *appKeywordReplyDo {
	return a.withDO(a.DO.Unscoped())
}

func (a appKeywordReplyDo) Create(values ...*model.AppKeywordReply) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

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

func (a appKeywordReplyDo) First() (*model.AppKeywordReply, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.AppKeywordReply), nil
	}
}

func (a appKeywordReplyDo) Take() (*model.AppKeywordReply, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.AppKeywordReply), nil
	}
}

func (a appKeywordReplyDo) Last() (*model.AppKeywordReply, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.AppKeywordReply), nil
	}
}

func (a appKeywordReplyDo) Find() ([]*model.AppKeywordReply, error) {
	result, err := a.DO.Find()
	return result.([]*model.AppKeywordReply), err
}

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

func (a appKeywordReplyDo) Attrs(attrs ...field.AssignExpr) *appKeywordReplyDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a appKeywordReplyDo) Assign(attrs ...field.AssignExpr) *appKeywordReplyDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

func (a appKeywordReplyDo) FirstOrInit() (*model.AppKeywordReply, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.AppKeywordReply), nil
	}
}

func (a appKeywordReplyDo) FirstOrCreate() (*model.AppKeywordReply, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.AppKeywordReply), nil
	}
}

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

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

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

func (a appKeywordReplyDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a appKeywordReplyDo) Delete(models ...*model.AppKeywordReply) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *appKeywordReplyDo) withDO(do gen.Dao) *appKeywordReplyDo {
	a.DO = *do.(*gen.DO)
	return a
}
