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

	"web3/app/service/demo/storage/mysql/model"
)

func newBlockTransaction(db *gorm.DB, opts ...gen.DOOption) blockTransaction {
	_blockTransaction := blockTransaction{}

	_blockTransaction.blockTransactionDo.UseDB(db, opts...)
	_blockTransaction.blockTransactionDo.UseModel(&model.BlockTransaction{})

	tableName := _blockTransaction.blockTransactionDo.TableName()
	_blockTransaction.ALL = field.NewAsterisk(tableName)
	_blockTransaction.Type = field.NewInt64(tableName, "type")
	_blockTransaction.Status = field.NewInt64(tableName, "status")
	_blockTransaction.BlockHash = field.NewString(tableName, "block_hash")
	_blockTransaction.BlockNumber = field.NewInt64(tableName, "block_number")
	_blockTransaction.BlockTimestamp = field.NewTime(tableName, "block_timestamp")
	_blockTransaction.TransactionHash = field.NewString(tableName, "transaction_hash")
	_blockTransaction.TransactionIndex = field.NewInt64(tableName, "transaction_index")
	_blockTransaction.FromAddress = field.NewString(tableName, "from_address")
	_blockTransaction.ToAddress = field.NewString(tableName, "to_address")
	_blockTransaction.Input = field.NewString(tableName, "input")
	_blockTransaction.Value = field.NewString(tableName, "value")
	_blockTransaction.Nonce = field.NewInt64(tableName, "nonce")
	_blockTransaction.ContractAddress = field.NewString(tableName, "contract_address")
	_blockTransaction.Gas = field.NewInt64(tableName, "gas")
	_blockTransaction.GasPrice = field.NewInt64(tableName, "gas_price")
	_blockTransaction.GasUsed = field.NewInt64(tableName, "gas_used")
	_blockTransaction.EffectiveGasPrice = field.NewInt64(tableName, "effective_gas_price")
	_blockTransaction.CumulativeGasUsed = field.NewInt64(tableName, "cumulative_gas_used")
	_blockTransaction.MaxFeePerGas = field.NewInt64(tableName, "max_fee_per_gas")
	_blockTransaction.MaxPriorityFeePerGas = field.NewInt64(tableName, "max_priority_fee_per_gas")
	_blockTransaction.R = field.NewString(tableName, "r")
	_blockTransaction.S = field.NewString(tableName, "s")
	_blockTransaction.V = field.NewInt64(tableName, "v")
	_blockTransaction.LogsCount = field.NewInt64(tableName, "logs_count")
	_blockTransaction.ChainID = field.NewInt64(tableName, "chain_id")
	_blockTransaction.ChainUniqueID = field.NewInt64(tableName, "chain_unique_id")
	_blockTransaction.CreatedAt = field.NewTime(tableName, "created_at")
	_blockTransaction.UpdatedAt = field.NewTime(tableName, "updated_at")

	_blockTransaction.fillFieldMap()

	return _blockTransaction
}

type blockTransaction struct {
	blockTransactionDo blockTransactionDo

	ALL                  field.Asterisk
	Type                 field.Int64
	Status               field.Int64
	BlockHash            field.String
	BlockNumber          field.Int64 // block number
	BlockTimestamp       field.Time  // Block Time
	TransactionHash      field.String
	TransactionIndex     field.Int64
	FromAddress          field.String
	ToAddress            field.String
	Input                field.String
	Value                field.String
	Nonce                field.Int64
	ContractAddress      field.String
	Gas                  field.Int64
	GasPrice             field.Int64
	GasUsed              field.Int64
	EffectiveGasPrice    field.Int64
	CumulativeGasUsed    field.Int64
	MaxFeePerGas         field.Int64
	MaxPriorityFeePerGas field.Int64
	R                    field.String
	S                    field.String
	V                    field.Int64
	LogsCount            field.Int64
	ChainID              field.Int64
	ChainUniqueID        field.Int64
	CreatedAt            field.Time // Create Time
	UpdatedAt            field.Time // Update Time

	fieldMap map[string]field.Expr
}

func (b blockTransaction) Table(newTableName string) *blockTransaction {
	b.blockTransactionDo.UseTable(newTableName)
	return b.updateTableName(newTableName)
}

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

func (b *blockTransaction) updateTableName(table string) *blockTransaction {
	b.ALL = field.NewAsterisk(table)
	b.Type = field.NewInt64(table, "type")
	b.Status = field.NewInt64(table, "status")
	b.BlockHash = field.NewString(table, "block_hash")
	b.BlockNumber = field.NewInt64(table, "block_number")
	b.BlockTimestamp = field.NewTime(table, "block_timestamp")
	b.TransactionHash = field.NewString(table, "transaction_hash")
	b.TransactionIndex = field.NewInt64(table, "transaction_index")
	b.FromAddress = field.NewString(table, "from_address")
	b.ToAddress = field.NewString(table, "to_address")
	b.Input = field.NewString(table, "input")
	b.Value = field.NewString(table, "value")
	b.Nonce = field.NewInt64(table, "nonce")
	b.ContractAddress = field.NewString(table, "contract_address")
	b.Gas = field.NewInt64(table, "gas")
	b.GasPrice = field.NewInt64(table, "gas_price")
	b.GasUsed = field.NewInt64(table, "gas_used")
	b.EffectiveGasPrice = field.NewInt64(table, "effective_gas_price")
	b.CumulativeGasUsed = field.NewInt64(table, "cumulative_gas_used")
	b.MaxFeePerGas = field.NewInt64(table, "max_fee_per_gas")
	b.MaxPriorityFeePerGas = field.NewInt64(table, "max_priority_fee_per_gas")
	b.R = field.NewString(table, "r")
	b.S = field.NewString(table, "s")
	b.V = field.NewInt64(table, "v")
	b.LogsCount = field.NewInt64(table, "logs_count")
	b.ChainID = field.NewInt64(table, "chain_id")
	b.ChainUniqueID = field.NewInt64(table, "chain_unique_id")
	b.CreatedAt = field.NewTime(table, "created_at")
	b.UpdatedAt = field.NewTime(table, "updated_at")

	b.fillFieldMap()

	return b
}

func (b *blockTransaction) WithContext(ctx context.Context) *blockTransactionDo {
	return b.blockTransactionDo.WithContext(ctx)
}

func (b blockTransaction) TableName() string { return b.blockTransactionDo.TableName() }

func (b blockTransaction) Alias() string { return b.blockTransactionDo.Alias() }

func (b *blockTransaction) 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 *blockTransaction) fillFieldMap() {
	b.fieldMap = make(map[string]field.Expr, 28)
	b.fieldMap["type"] = b.Type
	b.fieldMap["status"] = b.Status
	b.fieldMap["block_hash"] = b.BlockHash
	b.fieldMap["block_number"] = b.BlockNumber
	b.fieldMap["block_timestamp"] = b.BlockTimestamp
	b.fieldMap["transaction_hash"] = b.TransactionHash
	b.fieldMap["transaction_index"] = b.TransactionIndex
	b.fieldMap["from_address"] = b.FromAddress
	b.fieldMap["to_address"] = b.ToAddress
	b.fieldMap["input"] = b.Input
	b.fieldMap["value"] = b.Value
	b.fieldMap["nonce"] = b.Nonce
	b.fieldMap["contract_address"] = b.ContractAddress
	b.fieldMap["gas"] = b.Gas
	b.fieldMap["gas_price"] = b.GasPrice
	b.fieldMap["gas_used"] = b.GasUsed
	b.fieldMap["effective_gas_price"] = b.EffectiveGasPrice
	b.fieldMap["cumulative_gas_used"] = b.CumulativeGasUsed
	b.fieldMap["max_fee_per_gas"] = b.MaxFeePerGas
	b.fieldMap["max_priority_fee_per_gas"] = b.MaxPriorityFeePerGas
	b.fieldMap["r"] = b.R
	b.fieldMap["s"] = b.S
	b.fieldMap["v"] = b.V
	b.fieldMap["logs_count"] = b.LogsCount
	b.fieldMap["chain_id"] = b.ChainID
	b.fieldMap["chain_unique_id"] = b.ChainUniqueID
	b.fieldMap["created_at"] = b.CreatedAt
	b.fieldMap["updated_at"] = b.UpdatedAt
}

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

func (b blockTransaction) replaceDB(db *gorm.DB) blockTransaction {
	b.blockTransactionDo.ReplaceDB(db)
	return b
}

type blockTransactionDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

func (b blockTransactionDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *blockTransactionDo {
	return b.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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