# vRYR Mobile API v1

REST API für die vRYR Mobile App (Android/iOS).

## Base URL

**Development:** `http://localhost/airlines/ryr/api/v1/`  
**Production:** `https://vryr.vcrew-center.com/api/v1/`

## Authentication

Die API unterstützt zwei Authentifizierungsmethoden:

### 1. Session-basiert (Legacy, Web)
- Nach Login wird eine PHP-Session erstellt
- Session-Cookie wird automatisch vom Browser gesendet

### 2. Token-basiert (Mobile App)
- Nach Login erhält die App ein Bearer-Token
- Token muss in allen Requests im Header gesendet werden:
  ```
  Authorization: Bearer <token>
  ```

## API Endpoints

### Authentication

#### Login
```http
POST /auth/login
Content-Type: application/json

{
  "email": "pilot@vryr.com",
  "password": "password123"
}
```

**Response:**
```json
{
  "success": true,
  "message": "Login successful",
  "data": {
    "user": {
      "id": 123,
      "email": "pilot@vryr.com",
      "first_name": "John",
      "last_name": "Doe",
      "call_sign": "RYR123",
      "based_at": "DUB"
    },
    "session_id": "abc123...",
    "token": "eyJhbGc..."
  },
  "timestamp": "2026-01-14T12:00:00+00:00"
}
```

#### Logout
```http
POST /auth/logout
Authorization: Bearer <token>
```

#### Get Current User
```http
GET /auth/me
Authorization: Bearer <token>
```

---

### Flights

#### Get Flights
```http
GET /flights?status=all&limit=20&offset=0
Authorization: Bearer <token>
```

**Query Parameters:**
- `status` - Filter by status: `all`, `scheduled`, `completed` (default: `all`)
- `limit` - Max results (default: 20, max: 100)
- `offset` - Pagination offset (default: 0)

**Response:**
```json
{
  "success": true,
  "data": {
    "flights": [
      {
        "id": 1,
        "flight_number": "RYR123",
        "departure": {
          "icao": "EIDW",
          "name": "Dublin International Airport"
        },
        "arrival": {
          "icao": "EGLL",
          "name": "London Heathrow"
        },
        "aircraft": {
          "registration": "EI-ABC",
          "type": "B738"
        },
        "scheduled_departure": "2026-01-15 08:00:00",
        "status": "scheduled"
      }
    ],
    "count": 1,
    "offset": 0,
    "limit": 20
  }
}
```

---

### Fuel/FMC

#### Get Fuel/FMC Data
```http
GET /fuel_fmc
Authorization: Bearer <token>
```

**Response:**
```json
{
  "success": true,
  "data": {
    "has_data": true,
    "flight": {
      "departure": "EIDW",
      "arrival": "EGLL",
      "aircraft": "Boeing 737-800"
    },
    "fuel": {
      "block_fuel": 8500,
      "trip_fuel": 6200,
      "taxi_fuel": 200,
      "contingency": 310,
      "alternate": 1200,
      "reserve": 590,
      "extra": 0,
      "unit": "KG"
    },
    "weights": {
      "zfw": 62000,
      "tow": 70500,
      "payload": 12000
    },
    "route": "EIDW DCT EGLL",
    "altitude": 37000
  }
}
```

---

## Error Handling

Alle Fehler folgen diesem Format:

```json
{
  "success": false,
  "message": "Error description",
  "errors": null,
  "timestamp": "2026-01-14T12:00:00+00:00"
}
```

### HTTP Status Codes

- `200` - OK
- `201` - Created
- `400` - Bad Request
- `401` - Unauthorized
- `404` - Not Found
- `405` - Method Not Allowed
- `500` - Internal Server Error

## Development

### Testing mit cURL

```bash
# Login
curl -X POST http://localhost/airlines/ryr/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@test.com","password":"password"}'

# Get User
curl -X GET http://localhost/airlines/ryr/api/v1/auth/me \
  -H "Authorization: Bearer <token>"
```

### .htaccess Configuration

Stelle sicher, dass `.htaccess` für saubere URLs konfiguriert ist:

```apache
RewriteEngine On
RewriteRule ^v1/auth/(.*)$ v1/auth.php [L,QSA]
RewriteRule ^v1/flights$ v1/flights.php [L,QSA]
RewriteRule ^v1/fuel_fmc$ v1/fuel_fmc.php [L,QSA]
```
