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

	_aliyunAvatar.aliyunAvatarDo.UseDB(db, opts...)
	_aliyunAvatar.aliyunAvatarDo.UseModel(&model.AliyunAvatar{})

	tableName := _aliyunAvatar.aliyunAvatarDo.TableName()
	_aliyunAvatar.ALL = field.NewAsterisk(tableName)
	_aliyunAvatar.ID = field.NewInt64(tableName, "id")
	_aliyunAvatar.CreatedAt = field.NewTime(tableName, "created_at")
	_aliyunAvatar.UpdatedAt = field.NewTime(tableName, "updated_at")
	_aliyunAvatar.DeletedAt = field.NewField(tableName, "deleted_at")
	_aliyunAvatar.UserID = field.NewInt64(tableName, "user_id")
	_aliyunAvatar.BizID = field.NewString(tableName, "biz_id")
	_aliyunAvatar.AccessKeyID = field.NewString(tableName, "access_key_id")
	_aliyunAvatar.AccessKeySecret = field.NewString(tableName, "access_key_secret")
	_aliyunAvatar.AppID = field.NewString(tableName, "app_id")
	_aliyunAvatar.TenantID = field.NewString(tableName, "tenant_id")
	_aliyunAvatar.Response = field.NewString(tableName, "response")
	_aliyunAvatar.Token = field.NewString(tableName, "token")
	_aliyunAvatar.SessionID = field.NewString(tableName, "session_id")

	_aliyunAvatar.fillFieldMap()

	return _aliyunAvatar
}

// aliyunAvatar 阿里云数字人记录表
type aliyunAvatar struct {
	aliyunAvatarDo

	ALL             field.Asterisk
	ID              field.Int64
	CreatedAt       field.Time   // Create Time | 创建日期
	UpdatedAt       field.Time   // Update Time | 修改日期
	DeletedAt       field.Field  // Delete Time | 删除日期
	UserID          field.Int64  // userID
	BizID           field.String // bizId
	AccessKeyID     field.String
	AccessKeySecret field.String
	AppID           field.String
	TenantID        field.String
	Response        field.String
	Token           field.String
	SessionID       field.String

	fieldMap map[string]field.Expr
}

func (a aliyunAvatar) Table(newTableName string) *aliyunAvatar {
	a.aliyunAvatarDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

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

func (a *aliyunAvatar) updateTableName(table string) *aliyunAvatar {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.CreatedAt = field.NewTime(table, "created_at")
	a.UpdatedAt = field.NewTime(table, "updated_at")
	a.DeletedAt = field.NewField(table, "deleted_at")
	a.UserID = field.NewInt64(table, "user_id")
	a.BizID = field.NewString(table, "biz_id")
	a.AccessKeyID = field.NewString(table, "access_key_id")
	a.AccessKeySecret = field.NewString(table, "access_key_secret")
	a.AppID = field.NewString(table, "app_id")
	a.TenantID = field.NewString(table, "tenant_id")
	a.Response = field.NewString(table, "response")
	a.Token = field.NewString(table, "token")
	a.SessionID = field.NewString(table, "session_id")

	a.fillFieldMap()

	return a
}

func (a *aliyunAvatar) 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 *aliyunAvatar) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 13)
	a.fieldMap["id"] = a.ID
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["updated_at"] = a.UpdatedAt
	a.fieldMap["deleted_at"] = a.DeletedAt
	a.fieldMap["user_id"] = a.UserID
	a.fieldMap["biz_id"] = a.BizID
	a.fieldMap["access_key_id"] = a.AccessKeyID
	a.fieldMap["access_key_secret"] = a.AccessKeySecret
	a.fieldMap["app_id"] = a.AppID
	a.fieldMap["tenant_id"] = a.TenantID
	a.fieldMap["response"] = a.Response
	a.fieldMap["token"] = a.Token
	a.fieldMap["session_id"] = a.SessionID
}

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

func (a aliyunAvatar) replaceDB(db *gorm.DB) aliyunAvatar {
	a.aliyunAvatarDo.ReplaceDB(db)
	return a
}

type aliyunAvatarDo struct{ gen.DO }

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

func (a aliyunAvatarDo) Debug() IAliyunAvatarDo {
	return a.withDO(a.DO.Debug())
}

func (a aliyunAvatarDo) WithContext(ctx context.Context) IAliyunAvatarDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a aliyunAvatarDo) ReadDB() IAliyunAvatarDo {
	return a.Clauses(dbresolver.Read)
}

func (a aliyunAvatarDo) WriteDB() IAliyunAvatarDo {
	return a.Clauses(dbresolver.Write)
}

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

func (a aliyunAvatarDo) Clauses(conds ...clause.Expression) IAliyunAvatarDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a aliyunAvatarDo) Not(conds ...gen.Condition) IAliyunAvatarDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a aliyunAvatarDo) Or(conds ...gen.Condition) IAliyunAvatarDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a aliyunAvatarDo) Select(conds ...field.Expr) IAliyunAvatarDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a aliyunAvatarDo) Where(conds ...gen.Condition) IAliyunAvatarDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a aliyunAvatarDo) Order(conds ...field.Expr) IAliyunAvatarDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a aliyunAvatarDo) Distinct(cols ...field.Expr) IAliyunAvatarDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a aliyunAvatarDo) Omit(cols ...field.Expr) IAliyunAvatarDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a aliyunAvatarDo) Group(cols ...field.Expr) IAliyunAvatarDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a aliyunAvatarDo) Having(conds ...gen.Condition) IAliyunAvatarDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a aliyunAvatarDo) Limit(limit int) IAliyunAvatarDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a aliyunAvatarDo) Offset(offset int) IAliyunAvatarDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a aliyunAvatarDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAliyunAvatarDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a aliyunAvatarDo) Unscoped() IAliyunAvatarDo {
	return a.withDO(a.DO.Unscoped())
}

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

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

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

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

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

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

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

func (a aliyunAvatarDo) Attrs(attrs ...field.AssignExpr) IAliyunAvatarDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a aliyunAvatarDo) Assign(attrs ...field.AssignExpr) IAliyunAvatarDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

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

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

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

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

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