# Mock Video API Specification

You must build a mock backend server (`mock_video_api.py`) to test your pipeline against. 

## Server Configuration
*   **Host:** `127.0.0.1`
*   **Port:** `8000`
*   **Endpoint:** `POST /generate`
*   **Concurrency:** The server MUST be implemented using a concurrent framework (e.g., `http.server.ThreadingHTTPServer`, `FastAPI`, etc.) to process multiple incoming requests in parallel without blocking.
*   **Logging:** The server MUST log every incoming request to a file named `server_log.json` in JSON-lines format. Each line must be a JSON object containing: `{"timestamp": <float Unix time>, "prompt": <string prefix>, "status": "success"|"failed", "code": <int HTTP code>}`. This file must be appended to in a concurrency-safe manner.
*   **Host:** `127.0.0.1`
*   **Port:** `8000`
*   **Endpoint:** `POST /generate`

## Request Schema
The server must accept a JSON payload with the following structure:
```json
{
  "prompt": "String of the scene text",
  "glitch_factor": 0.0,
  "motion": 2.0
}
```

## Processing Logic
To accurately simulate the real Runway/Pika APIs:
1.  **Latency:** The server must sleep for exactly `0.3` seconds on every request.
2.  **Flakiness (Rate Limiting Simulation):** The server must have a 30% chance (`0.3` probability) of failing. When it fails, it must return an HTTP status code of either `429` (Too Many Requests) or `503` (Service Unavailable).
3.  **Deterministic Grading Support:** To prevent grading timeouts due to unlucky streaks, the server MUST read the environment variable `MOCK_API_SEED`. If present, it must use this value to seed the Python `random` module (e.g., `random.seed(int(os.environ.get("MOCK_API_SEED")))`) before serving requests.

## Success Response Schema (HTTP 200)
If the request does not fail, return the following JSON:
```json
{
  "status": "success",
  "video_url": "https://mock-video-api.local/renders/shot_<id>.mp4",
  "applied_glitch": <float from request>,
  "applied_motion": <float from request>
}
```
*Note: The `<id>` should be a deterministic 8-character string generated by calculating the SHA-256 hex digest of the prompt string and slicing the first 8 characters (e.g., `hashlib.sha256(prompt_text.encode('utf-8')).hexdigest()[:8]`).*