2025-09-17 19:30:17 +07:00
|
|
|
package processor
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-18 02:01:50 +07:00
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2025-09-17 19:30:17 +07:00
|
|
|
"apskel-pos-be/internal/models"
|
|
|
|
|
"apskel-pos-be/internal/repository"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CustomerPointsProcessor struct {
|
2026-09-30 09:15:26 +07:00
|
|
|
walletQuery *WalletQueryProcessor
|
|
|
|
|
gameRepo *repository.GameRepository
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
|
2026-09-30 09:15:26 +07:00
|
|
|
func NewCustomerPointsProcessor(walletQuery *WalletQueryProcessor, gameRepo *repository.GameRepository) *CustomerPointsProcessor {
|
2025-09-17 19:30:17 +07:00
|
|
|
return &CustomerPointsProcessor{
|
2026-09-30 09:15:26 +07:00
|
|
|
walletQuery: walletQuery,
|
|
|
|
|
gameRepo: gameRepo,
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
// Existing gamification methods - placeholder implementations
|
2025-09-17 19:30:17 +07:00
|
|
|
func (p *CustomerPointsProcessor) CreateCustomerPoints(ctx context.Context, req *models.CreateCustomerPointsRequest) (*models.CustomerPointsResponse, error) {
|
2025-09-18 02:01:50 +07:00
|
|
|
// TODO: Implement this method
|
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *CustomerPointsProcessor) GetCustomerPoints(ctx context.Context, id uuid.UUID) (*models.CustomerPointsResponse, error) {
|
2025-09-18 02:01:50 +07:00
|
|
|
// TODO: Implement this method
|
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *CustomerPointsProcessor) GetCustomerPointsByCustomerID(ctx context.Context, customerID uuid.UUID) (*models.CustomerPointsResponse, error) {
|
2025-09-18 02:01:50 +07:00
|
|
|
// TODO: Implement this method
|
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) ListCustomerPoints(ctx context.Context, query *models.ListCustomerPointsQuery) (*models.PaginatedCustomerPointsResponse, error) {
|
|
|
|
|
// Return empty paginated response for now
|
|
|
|
|
return &models.PaginatedCustomerPointsResponse{
|
|
|
|
|
Data: []models.CustomerPointsResponse{},
|
|
|
|
|
TotalCount: 0,
|
|
|
|
|
Page: 1,
|
|
|
|
|
Limit: 10,
|
|
|
|
|
TotalPages: 0,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
2025-09-17 19:30:17 +07:00
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) UpdateCustomerPoints(ctx context.Context, id uuid.UUID, req *models.UpdateCustomerPointsRequest) (*models.CustomerPointsResponse, error) {
|
|
|
|
|
// TODO: Implement this method
|
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
|
}
|
2025-09-17 19:30:17 +07:00
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) DeleteCustomerPoints(ctx context.Context, id uuid.UUID) error {
|
|
|
|
|
// TODO: Implement this method
|
|
|
|
|
return fmt.Errorf("not implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *CustomerPointsProcessor) AddPoints(ctx context.Context, customerID uuid.UUID, points int64) (*models.CustomerPointsResponse, error) {
|
|
|
|
|
// TODO: Implement this method
|
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *CustomerPointsProcessor) DeductPoints(ctx context.Context, customerID uuid.UUID, points int64) (*models.CustomerPointsResponse, error) {
|
|
|
|
|
// TODO: Implement this method
|
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 09:15:26 +07:00
|
|
|
// The three endpoints below are the customer app's balance screens. They read the
|
|
|
|
|
// EnakPoint & EnakCoin wallet; customer_points and customer_tokens are no longer used
|
|
|
|
|
// for balances (docs/prd-point-coin.md §9).
|
|
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerTotalPointsAPI(ctx context.Context, customerID string) (*models.GetCustomerPointsResponse, error) {
|
2026-09-30 09:15:26 +07:00
|
|
|
id, err := parseWalletCustomerID(customerID)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 09:15:26 +07:00
|
|
|
return nil, err
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2026-09-30 09:15:26 +07:00
|
|
|
data, err := p.walletQuery.LegacyPoints(ctx, id)
|
2025-09-18 02:01:50 +07:00
|
|
|
if err != nil {
|
2026-09-30 09:15:26 +07:00
|
|
|
return nil, fmt.Errorf("failed to get customer points: %w", err)
|
2025-09-18 02:01:50 +07:00
|
|
|
}
|
|
|
|
|
return &models.GetCustomerPointsResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Customer points retrieved successfully.",
|
2026-09-30 09:15:26 +07:00
|
|
|
Data: data,
|
2025-09-17 19:30:17 +07:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerTotalTokensAPI(ctx context.Context, customerID string) (*models.GetCustomerTokensResponse, error) {
|
2026-09-30 09:15:26 +07:00
|
|
|
id, err := parseWalletCustomerID(customerID)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 09:15:26 +07:00
|
|
|
return nil, err
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2026-09-30 09:15:26 +07:00
|
|
|
data, err := p.walletQuery.LegacyTokens(ctx, id)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 09:15:26 +07:00
|
|
|
return nil, fmt.Errorf("failed to get customer tokens: %w", err)
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2025-09-18 02:01:50 +07:00
|
|
|
return &models.GetCustomerTokensResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Customer tokens retrieved successfully.",
|
2026-09-30 09:15:26 +07:00
|
|
|
Data: data,
|
2025-09-18 02:01:50 +07:00
|
|
|
}, nil
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerWalletAPI(ctx context.Context, customerID string) (*models.GetCustomerWalletResponse, error) {
|
2026-09-30 09:15:26 +07:00
|
|
|
id, err := parseWalletCustomerID(customerID)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 09:15:26 +07:00
|
|
|
return nil, err
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2026-09-30 09:15:26 +07:00
|
|
|
data, err := p.walletQuery.Summary(ctx, id)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 09:15:26 +07:00
|
|
|
return nil, fmt.Errorf("failed to get customer wallet: %w", err)
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2025-09-18 02:01:50 +07:00
|
|
|
return &models.GetCustomerWalletResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Customer wallet retrieved successfully.",
|
2026-09-30 09:15:26 +07:00
|
|
|
Data: data,
|
2025-09-18 02:01:50 +07:00
|
|
|
}, nil
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2025-09-18 12:01:20 +07:00
|
|
|
|
2026-09-30 09:15:26 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerWalletTransactionsAPI(ctx context.Context, customerID string, query models.ListCustomerWalletTransactionsQuery) (*models.PaginatedResponse[models.CustomerWalletTransaction], error) {
|
|
|
|
|
id, err := parseWalletCustomerID(customerID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return p.walletQuery.Transactions(ctx, id, query)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseWalletCustomerID(customerID string) (uuid.UUID, error) {
|
|
|
|
|
id, err := uuid.Parse(customerID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return uuid.Nil, fmt.Errorf("%w: invalid customer id", ErrInvalidWalletQuery)
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 12:01:20 +07:00
|
|
|
// GetCustomerGamesAPI gets active SPIN games for customers
|
|
|
|
|
func (p *CustomerPointsProcessor) GetCustomerGamesAPI(ctx context.Context) (*models.GetCustomerGamesResponse, error) {
|
|
|
|
|
// Get active SPIN games
|
|
|
|
|
games, err := p.gameRepo.GetActiveSpinGames(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to get active SPIN games: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert to response format
|
|
|
|
|
var gameResponses []models.CustomerGameResponse
|
|
|
|
|
for _, game := range games {
|
|
|
|
|
var prizeResponses []models.CustomerGamePrizeResponse
|
|
|
|
|
for _, prize := range game.Prizes {
|
|
|
|
|
prizeResponses = append(prizeResponses, models.CustomerGamePrizeResponse{
|
|
|
|
|
ID: prize.ID,
|
|
|
|
|
GameID: prize.GameID,
|
|
|
|
|
Name: prize.Name,
|
|
|
|
|
Image: prize.Image,
|
|
|
|
|
Metadata: (*map[string]interface{})(&prize.Metadata),
|
|
|
|
|
CreatedAt: prize.CreatedAt,
|
|
|
|
|
UpdatedAt: prize.UpdatedAt,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameResponses = append(gameResponses, models.CustomerGameResponse{
|
|
|
|
|
ID: game.ID,
|
|
|
|
|
Name: game.Name,
|
|
|
|
|
Type: string(game.Type),
|
|
|
|
|
IsActive: game.IsActive,
|
|
|
|
|
Metadata: (*map[string]interface{})(&game.Metadata),
|
|
|
|
|
Prizes: prizeResponses,
|
|
|
|
|
CreatedAt: game.CreatedAt,
|
|
|
|
|
UpdatedAt: game.UpdatedAt,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &models.GetCustomerGamesResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Customer games retrieved successfully.",
|
|
|
|
|
Data: &models.GetCustomerGamesResponseData{
|
|
|
|
|
Games: gameResponses,
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetFerrisWheelGameAPI gets the Ferris Wheel game for customers
|
|
|
|
|
func (p *CustomerPointsProcessor) GetFerrisWheelGameAPI(ctx context.Context) (*models.GetFerrisWheelGameResponse, error) {
|
|
|
|
|
// Get Ferris Wheel game
|
|
|
|
|
game, err := p.gameRepo.GetFerrisWheelGame(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to get Ferris Wheel game: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert prizes to response format
|
|
|
|
|
var prizeResponses []models.CustomerGamePrizeResponse
|
|
|
|
|
for _, prize := range game.Prizes {
|
|
|
|
|
prizeResponses = append(prizeResponses, models.CustomerGamePrizeResponse{
|
|
|
|
|
ID: prize.ID,
|
|
|
|
|
GameID: prize.GameID,
|
|
|
|
|
Name: prize.Name,
|
|
|
|
|
Image: prize.Image,
|
|
|
|
|
Metadata: (*map[string]interface{})(&prize.Metadata),
|
|
|
|
|
CreatedAt: prize.CreatedAt,
|
|
|
|
|
UpdatedAt: prize.UpdatedAt,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert game to response format
|
|
|
|
|
gameResponse := models.CustomerGameResponse{
|
|
|
|
|
ID: game.ID,
|
|
|
|
|
Name: game.Name,
|
|
|
|
|
Type: string(game.Type),
|
|
|
|
|
IsActive: game.IsActive,
|
|
|
|
|
Metadata: (*map[string]interface{})(&game.Metadata),
|
|
|
|
|
Prizes: prizeResponses,
|
|
|
|
|
CreatedAt: game.CreatedAt,
|
|
|
|
|
UpdatedAt: game.UpdatedAt,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &models.GetFerrisWheelGameResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Ferris Wheel game retrieved successfully.",
|
|
|
|
|
Data: &models.GetFerrisWheelGameResponseData{
|
2025-09-18 12:42:07 +07:00
|
|
|
Game: gameResponse,
|
2025-09-18 12:01:20 +07:00
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|