# Implementation Plan - Reward Shop

## Goal
Implement a "Reward Shop" where users can spend their hard-earned XP on virtual or real-world rewards. This enhances the gamification loop.

## User Review Required
> [!IMPORTANT]
> **Schema Changes**: We will need to reset the database or run migrations to add the new `rewards` and `user_rewards` tables. Since we are in dev/prototype mode, I will likely push schema changes which might require a DB reset if we don't have a migration system set up (currently using `drizzle-kit push`).

## Proposed Changes

### Database Schema (`shared/schema.ts`)
#### [NEW] `rewards` table
- `id`: serial primary key
- `title`: text (localizable key or raw text)
- `description`: text
- `cost`: integer (XP cost)
- `icon`: text (lucide icon name)
- `type`: text ('virtual', 'real_world', 'feature_unlock')
- `is_system`: boolean (default true, for built-in rewards)

#### [NEW] `user_rewards` table
- `id`: serial primary key
- `user_id`: integer (ref users)
- `reward_id`: integer (ref rewards)
- `purchased_at`: timestamp

### Backend (`server/routes.ts`)
#### [NEW] `GET /api/rewards`
- Returns list of all available rewards.
- Checks `user_rewards` to mark which ones are already owned (unique/one-time rewards).

#### [NEW] `POST /api/rewards/buy`
- Params: `rewardId`, `userId`
- Logic:
    1. Check user XP balance.
    2. If sufficient, deduct XP.
    3. Insert into `user_rewards`.
    4. Return success + new XP balance.

### Frontend
#### [MODIFY] `client/src/pages/AchievementsPage.tsx`
- Add a new Tab: "Belohnungen" (Rewards).
- Render a grid of "Reward Cards".

#### [NEW] `client/src/components/gamification/RewardCard.tsx`
- Displays Icon, Title, Description, Cost.
- "Buy" button (Green if affordable, Grey if not).
- "Owned" badge if already purchased.

### Translations (`en.json`, `de.json`)
- Add `rewards` namespace.
- Keys: `shopTitle`, `buy`, `insufficientFunds`, `owned`.

## Verification Plan
### Automated Tests
- None planned for now (prototyping).

### Manual Verification
1. **Browse**: Check if rewards load in the new tab.
2. **Buy (Success)**: Click buy on an affordable item -> XP decreases, item marked owned.
3. **Buy (Fail)**: Click buy on expensive item -> Error toast "Not enough XP".

# Localization Polish & E2E Testing Plan

## Goal
address the user's request to polish localization (Audit Logs) and add E2E tests for Recurring Tasks and Data Export.

## Proposed Changes

### Localization
#### [MODIFY] [en.json](file:///Users/paul/Development/task-manager/client/src/i18n/locales/en.json) & [de.json](file:///Users/paul/Development/task-manager/client/src/i18n/locales/de.json)
- Add `audit` section with translations for:
    - Actions: `CREATE`, `UPDATE`, `DELETE`, `COMPLETE`, `GENERATE_API_KEY`, `REVOKE_API_KEY`, `EXPORT_DATA`, `LOGIN`, `LOGOUT`
    - Entities: `TASK`, `USER`, `LABEL`, `SETTINGS`, `AI_CONFIG`, `MCP`
    - Sources: `WEB`, `AI`, `SYSTEM`, `Unknown`

#### [MODIFY] [AuditLogsTable.tsx](file:///Users/paul/Development/task-manager/client/src/components/admin/AuditLogsTable.tsx)
- Use `t('audit.action.' + log.action)` for lookup.
- Use `t('audit.entity.' + log.entityType)`.
- Use `t('audit.source.' + log.source)`.
- Use localized date formatting (maybe `Intl.DateTimeFormat` or `date-fns` with `de` locale from `date-fns/locale`).

### E2E Testing
#### [NEW] [tests/e2e/recurring_tasks.spec.ts](file:///Users/paul/Development/task-manager/tests/e2e/recurring_tasks.spec.ts)
- Test Case:
    1.  Login as User.
    2.  Create Task "Recurring Task Test" with Recurrence: Daily, Every 1 Day.
    3.  Verify task appears with recurrence icon.
    4.  Complete task.
    5.  Verify original is "Done".
    6.  Verify NEW task "Recurring Task Test" appears (Due tomorrow).

#### [NEW] [tests/e2e/data_export.spec.ts](file:///Users/paul/Development/task-manager/tests/e2e/data_export.spec.ts)
- Test Case:
    1.  Login as User.
    2.  Nav to Settings.
    3.  Intercept `POST /api/user/export`.
    4.  Click "Export Data".
    5.  Verify request payload (includes tasks, labels).
    6.  Verify response status 200 and JSON structure.

## Verification
- Run `npm run test:e2e` (or specific specs).
- Manual check of Audit Logs page.
