package postgres

import (
	"context"

	"github.com/break/junhong_cmp_fiber/internal/model"
	"github.com/redis/go-redis/v9"
	"gorm.io/gorm"
)

type WalletTransactionStore struct {
	db    *gorm.DB
	redis *redis.Client
}

func NewWalletTransactionStore(db *gorm.DB, redis *redis.Client) *WalletTransactionStore {
	return &WalletTransactionStore{
		db:    db,
		redis: redis,
	}
}

func (s *WalletTransactionStore) CreateWithTx(ctx context.Context, tx *gorm.DB, transaction *model.WalletTransaction) error {
	return tx.WithContext(ctx).Create(transaction).Error
}

func (s *WalletTransactionStore) Create(ctx context.Context, transaction *model.WalletTransaction) error {
	return s.db.WithContext(ctx).Create(transaction).Error
}

func (s *WalletTransactionStore) GetByID(ctx context.Context, id uint) (*model.WalletTransaction, error) {
	var tx model.WalletTransaction
	if err := s.db.WithContext(ctx).First(&tx, id).Error; err != nil {
		return nil, err
	}
	return &tx, nil
}
