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

import (
	"context"

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

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

	"gorm.io/plugin/dbresolver"

	"cheemshappy_pay/internal/model"
)

func newSysWallet(db *gorm.DB, opts ...gen.DOOption) sysWallet {
	_sysWallet := sysWallet{}

	_sysWallet.sysWalletDo.UseDB(db, opts...)
	_sysWallet.sysWalletDo.UseModel(&model.SysWallet{})

	tableName := _sysWallet.sysWalletDo.TableName()
	_sysWallet.ALL = field.NewAsterisk(tableName)
	_sysWallet.ID = field.NewInt64(tableName, "id")
	_sysWallet.Ac = field.NewString(tableName, "ac")
	_sysWallet.PriKey = field.NewString(tableName, "pri_key")
	_sysWallet.Mnemonic = field.NewString(tableName, "mnemonic")
	_sysWallet.Path = field.NewString(tableName, "path")
	_sysWallet.Remark = field.NewString(tableName, "remark")
	_sysWallet.CreatedAt = field.NewTime(tableName, "created_at")
	_sysWallet.UpdatedAt = field.NewTime(tableName, "updated_at")
	_sysWallet.DeletedAt = field.NewField(tableName, "deleted_at")
	_sysWallet.CurrentIndex = field.NewInt32(tableName, "current_index")
	_sysWallet.Version = field.NewInt32(tableName, "version")

	_sysWallet.fillFieldMap()

	return _sysWallet
}

type sysWallet struct {
	sysWalletDo

	ALL          field.Asterisk
	ID           field.Int64
	Ac           field.String // 钱包地址
	PriKey       field.String // 私钥
	Mnemonic     field.String // 助记词
	Path         field.String // 钱包路径
	Remark       field.String // 备注
	CreatedAt    field.Time
	UpdatedAt    field.Time
	DeletedAt    field.Field
	CurrentIndex field.Int32 // 当前派生索引
	Version      field.Int32

	fieldMap map[string]field.Expr
}

func (s sysWallet) Table(newTableName string) *sysWallet {
	s.sysWalletDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s sysWallet) As(alias string) *sysWallet {
	s.sysWalletDo.DO = *(s.sysWalletDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *sysWallet) updateTableName(table string) *sysWallet {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt64(table, "id")
	s.Ac = field.NewString(table, "ac")
	s.PriKey = field.NewString(table, "pri_key")
	s.Mnemonic = field.NewString(table, "mnemonic")
	s.Path = field.NewString(table, "path")
	s.Remark = field.NewString(table, "remark")
	s.CreatedAt = field.NewTime(table, "created_at")
	s.UpdatedAt = field.NewTime(table, "updated_at")
	s.DeletedAt = field.NewField(table, "deleted_at")
	s.CurrentIndex = field.NewInt32(table, "current_index")
	s.Version = field.NewInt32(table, "version")

	s.fillFieldMap()

	return s
}

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

func (s *sysWallet) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 11)
	s.fieldMap["id"] = s.ID
	s.fieldMap["ac"] = s.Ac
	s.fieldMap["pri_key"] = s.PriKey
	s.fieldMap["mnemonic"] = s.Mnemonic
	s.fieldMap["path"] = s.Path
	s.fieldMap["remark"] = s.Remark
	s.fieldMap["created_at"] = s.CreatedAt
	s.fieldMap["updated_at"] = s.UpdatedAt
	s.fieldMap["deleted_at"] = s.DeletedAt
	s.fieldMap["current_index"] = s.CurrentIndex
	s.fieldMap["version"] = s.Version
}

func (s sysWallet) clone(db *gorm.DB) sysWallet {
	s.sysWalletDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s sysWallet) replaceDB(db *gorm.DB) sysWallet {
	s.sysWalletDo.ReplaceDB(db)
	return s
}

type sysWalletDo struct{ gen.DO }

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

func (s sysWalletDo) Debug() ISysWalletDo {
	return s.withDO(s.DO.Debug())
}

func (s sysWalletDo) WithContext(ctx context.Context) ISysWalletDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sysWalletDo) ReadDB() ISysWalletDo {
	return s.Clauses(dbresolver.Read)
}

func (s sysWalletDo) WriteDB() ISysWalletDo {
	return s.Clauses(dbresolver.Write)
}

func (s sysWalletDo) Session(config *gorm.Session) ISysWalletDo {
	return s.withDO(s.DO.Session(config))
}

func (s sysWalletDo) Clauses(conds ...clause.Expression) ISysWalletDo {
	return s.withDO(s.DO.Clauses(conds...))
}

func (s sysWalletDo) Returning(value interface{}, columns ...string) ISysWalletDo {
	return s.withDO(s.DO.Returning(value, columns...))
}

func (s sysWalletDo) Not(conds ...gen.Condition) ISysWalletDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sysWalletDo) Or(conds ...gen.Condition) ISysWalletDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sysWalletDo) Select(conds ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sysWalletDo) Where(conds ...gen.Condition) ISysWalletDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s sysWalletDo) Order(conds ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sysWalletDo) Distinct(cols ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sysWalletDo) Omit(cols ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.Omit(cols...))
}

func (s sysWalletDo) Join(table schema.Tabler, on ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.Join(table, on...))
}

func (s sysWalletDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.LeftJoin(table, on...))
}

func (s sysWalletDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.RightJoin(table, on...))
}

func (s sysWalletDo) Group(cols ...field.Expr) ISysWalletDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sysWalletDo) Having(conds ...gen.Condition) ISysWalletDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sysWalletDo) Limit(limit int) ISysWalletDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sysWalletDo) Offset(offset int) ISysWalletDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sysWalletDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysWalletDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sysWalletDo) Unscoped() ISysWalletDo {
	return s.withDO(s.DO.Unscoped())
}

func (s sysWalletDo) Create(values ...*model.SysWallet) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

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

func (s sysWalletDo) First() (*model.SysWallet, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysWallet), nil
	}
}

func (s sysWalletDo) Take() (*model.SysWallet, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysWallet), nil
	}
}

func (s sysWalletDo) Last() (*model.SysWallet, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysWallet), nil
	}
}

func (s sysWalletDo) Find() ([]*model.SysWallet, error) {
	result, err := s.DO.Find()
	return result.([]*model.SysWallet), err
}

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

func (s sysWalletDo) Attrs(attrs ...field.AssignExpr) ISysWalletDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sysWalletDo) Assign(attrs ...field.AssignExpr) ISysWalletDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s sysWalletDo) FirstOrInit() (*model.SysWallet, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysWallet), nil
	}
}

func (s sysWalletDo) FirstOrCreate() (*model.SysWallet, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.SysWallet), nil
	}
}

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

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

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

func (s sysWalletDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s sysWalletDo) Delete(models ...*model.SysWallet) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *sysWalletDo) withDO(do gen.Dao) *sysWalletDo {
	s.DO = *do.(*gen.DO)
	return s
}
