package processor import ( "context" "fmt" "apskel-pos-be/internal/models" "github.com/google/uuid" ) type CustomerPointsProcessor struct { walletQuery *WalletQueryProcessor } func NewCustomerPointsProcessor(walletQuery *WalletQueryProcessor) *CustomerPointsProcessor { return &CustomerPointsProcessor{ walletQuery: walletQuery, } } // The 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). func (p *CustomerPointsProcessor) GetCustomerTotalPointsAPI(ctx context.Context, customerID string) (*models.GetCustomerPointsResponse, error) { id, err := parseWalletCustomerID(customerID) if err != nil { return nil, err } data, err := p.walletQuery.LegacyPoints(ctx, id) if err != nil { return nil, fmt.Errorf("failed to get customer points: %w", err) } return &models.GetCustomerPointsResponse{ Status: "SUCCESS", Message: "Customer points retrieved successfully.", Data: data, }, nil } func (p *CustomerPointsProcessor) GetCustomerWalletAPI(ctx context.Context, customerID string) (*models.GetCustomerWalletResponse, error) { id, err := parseWalletCustomerID(customerID) if err != nil { return nil, err } data, err := p.walletQuery.Summary(ctx, id) if err != nil { return nil, fmt.Errorf("failed to get customer wallet: %w", err) } return &models.GetCustomerWalletResponse{ Status: "SUCCESS", Message: "Customer wallet retrieved successfully.", Data: data, }, nil } 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 } func (p *CustomerPointsProcessor) GetCustomerWalletExpiringAPI(ctx context.Context, customerID string) (*models.CustomerWalletExpiringList, error) { id, err := parseWalletCustomerID(customerID) if err != nil { return nil, err } return p.walletQuery.Expiring(ctx, id) }