# Games Configuration — ALGA ARENA Esports Platform

**Date:** 2026-07-20

## Overview

Games are admin-managed catalog entries with per-game metadata (platforms, regions, ranks, roles, characters). Players attach **player game profiles** to games they play.

---

## Catalog Structure

### Model: `Game`

**Public routes:**

- `GET /games` → `GameController@index`
- `GET /games/{game:slug}` → `GameController@show`

**Admin routes:** `admin/games` resource (index, create, store, edit, update, destroy — no show)

### Feature flags (per game)

| Column | Purpose |
|--------|---------|
| `supports_ranks` | Show rank selectors |
| `supports_roles` | Allow role multi-select |
| `supports_characters` | Allow character picks |
| `supports_regions` | Region dropdown |
| `supports_servers` | Server dropdown (requires region) |

### Related catalog models

- `GameTranslation` — localized name/description (`en`, `ar` seeded)
- `GamePlatform`, `GameRegion`, `GameServer`
- `GameRank`, `GameRole`, `GameCharacter`, `GameMode`

All child records cascade delete with parent game.

---

## Seeded Games (`GameSeeder`)

| Slug | Name | Notable config |
|------|------|----------------|
| `valorant` | Valorant | PC; roles; ranks |
| `league-of-legends` | League of Legends | PC; roles; ranks |
| `ea-sports-fc` | EA Sports FC | PS/Xbox/PC |
| `tekken` | Tekken | PS/Xbox/PC; characters |
| `pubg-mobile` | PUBG Mobile | Android/iOS |
| `counter-strike-2` | Counter-Strike 2 | PC |
| `mobile-legends` | Mobile Legends | Android/iOS |

Seeder uses `updateOrCreate` by slug — safe to re-run.

---

## Admin Game Management

**Controller:** `Admin\GameController`  
**Authorization:** Admin middleware + `GamePolicy@manage`

### Operations

- List/create/edit/delete games
- Manage nested catalog via forms (platforms, regions, ranks, roles, characters)
- Upload logo/cover to `games` disk
- Set `status` (active/inactive) and `sort_order`

**Audit:** Changes should be logged via `AuditLogger` where implemented in controller actions.

---

## Player Game Profiles

**Routes:** `/profile/games/*`  
**Controller:** `PlayerGameProfileController`  
**Actions:** `CreatePlayerGameProfileAction`, `UpdatePlayerGameProfileAction`  
**Trait:** `ValidatesGameCatalogSelections` — ensures rank/role/character/platform IDs belong to the selected game

### Create flow

```
GET /profile/games/create
    ↓ User selects game + in-game name + catalog options
POST /profile/games
    ↓
CreatePlayerGameProfileAction
    ├── validateGameCatalogSelections(game, data)
    ├── If is_primary_game: unset other primaries
    ├── Create player_game_profiles row
    └── Sync roles, characters, platforms pivot tables
```

### Stored fields

- `in_game_name`, `external_game_id`
- `current_rank_id`, `highest_rank_id`
- `primary_platform_id`, `region_id`, `server_id`
- `years_of_experience`, `skill_level`, `biography`
- `is_primary_game`, `is_public`

### Constraints

- One profile per `(player_profile_id, game_id)` — DB unique index
- Soft deletes on `player_game_profiles`

---

## Query Layer

**`GameCatalogQuery`** — used by record/video controllers to load active games for forms.

---

## Configuration Files

**`config/esports.php`** (if present) — default locale, supported locales.  
**`config/filesystems.php`** — `games` disk at `storage/app/public/games`.

---

## Preview vs Production

| Aspect | Preview (`/preview/games`) | Production (`/games`) |
|--------|---------------------------|----------------------|
| Data source | `MockDataService` / JSON | Database |
| Slugs | Fictional (ValoStrike, etc.) | Real slugs from seeder |
| Backend | No DB required | Requires migrations + seed |

Preview routes preserved intentionally until full UI parity.

---

## Event Integration

Events require a `game_id`. Registration form only lists player game profiles matching the event's game:

```php
$profile->gameProfiles()->where('game_id', $event->game_id)
```

---

## Diagram

```mermaid
flowchart TB
    subgraph Admin
        AG[Admin GameController]
        GC[(games + catalog tables)]
        AG --> GC
    end

    subgraph Player
        PG[PlayerGameProfileController]
        PGP[(player_game_profiles)]
        PG --> PGP
    end

    GC --> PGP
    PGP --> REC[Player Records]
    PGP --> VID[Player Videos]
    PGP --> REG[Event Registration]
```
