# 🚀 Start Here - Amadeus Integration

## Your Credentials Are Ready!

Since you already have your Amadeus API Key and Secret, let's get you up and running in 3 simple steps.

---

## Step 1: Add Your Credentials (2 minutes)

Run this script and enter your credentials when prompted:

```bash
./configure-amadeus-credentials.sh
```

**What it does:**
- Adds your API Key and Secret to `.env` file
- Rebuilds the application
- Restarts with your credentials
- Verifies authentication

---

## Step 2: Test the Integration (1 minute)

Run the comprehensive test:

```bash
./test-amadeus-complete.sh
```

**What it tests:**
- Application health
- Amadeus authentication
- Real flight search (MAD → NYC)
- Circuit breaker status
- Error checking

---

## Step 3: Try Your First Booking (5 minutes)

Run the interactive tutorial:

```bash
./first-booking-tutorial.sh
```

**What it does:**
- Searches for real flights
- Creates an agency
- Makes a booking
- Issues a ticket
- Shows you the complete flow

---

## Quick Commands

### View Logs
```bash
# All logs
docker-compose logs -f app

# Amadeus logs only
docker-compose logs app | grep -i amadeus

# Authentication logs
docker-compose logs app | grep -i "amadeus" | grep -i "auth"
```

### Check Status
```bash
# Application health
curl http://localhost:8081/actuator/health | jq

# Amadeus API status
curl http://localhost:8081/actuator/health | jq '.components.amadeusApi'

# Circuit breaker
curl http://localhost:8081/actuator/health | jq '.components.circuitBreakers.details.amadeus'
```

### Test Flight Search
```bash
# Get token
TOKEN=$(curl -s -X POST "http://localhost:8080/realms/b2b-flight-platform/protocol/openid-connect/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=superadmin" \
  -d "password=admin123" \
  -d "grant_type=password" \
  -d "client_id=b2b-flight-backend" \
  -d "client_secret=b2b-flight-backend-secret" | jq -r '.access_token')

# Search flights
curl -X POST "http://localhost:8081/api/v1/flights/search" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "originLocationCode": "MAD",
    "destinationLocationCode": "NYC",
    "departureDate": "2026-03-15",
    "adults": 1,
    "travelClass": "ECONOMY",
    "currencyCode": "EUR"
  }' | jq '.'
```

---

## What You'll See

### ✅ Success Indicators

**In logs:**
```
Successfully authenticated with Amadeus API. Token expires in 1799 seconds
Successfully retrieved X flight offers from Amadeus
```

**In test output:**
```
✅ Application is running
✅ Amadeus authentication successful
✅ Flight search successful! Found X real offers from Amadeus
✅ Circuit breaker is CLOSED (healthy)
```

### ❌ If Something Goes Wrong

**"Credentials not configured"**
- Make sure you ran `./configure-amadeus-credentials.sh`
- Check `.env` file has your credentials

**"Failed to authenticate"**
- Verify your API Key and Secret are correct
- Check you're using test environment credentials
- Try regenerating credentials in Amadeus dashboard

**"No offers found"**
- This might be normal for some routes/dates
- Try different dates (future dates work better)
- Try popular routes (MAD-NYC, LON-NYC, PAR-NYC)

---

## Explore More

### Swagger UI
Interactive API documentation:
```
http://localhost:8081/swagger-ui.html
```

### Documentation
- **Complete Guide**: `AMADEUS_INTEGRATION_README.md`
- **Quick Reference**: `docs/AMADEUS_QUICK_REFERENCE.md`
- **Tutorial**: `docs/AMADEUS_FIRST_BOOKING_TUTORIAL.md`

### Available APIs
- ✈️ Flight Search
- 📋 Fare Rules
- 📝 Booking Creation
- 🎫 Ticket Issuance
- ❌ Ticket Void
- 💰 Ticket Refund

---

## Troubleshooting

### Application Not Running
```bash
docker-compose up -d
```

### Restart Application
```bash
docker-compose restart app
```

### Rebuild Everything
```bash
mvn clean package -DskipTests
docker-compose down
docker-compose up -d
```

### Check All Services
```bash
docker-compose ps
```

---

## Need Help?

1. **Check logs**: `docker-compose logs app | grep -i amadeus`
2. **Read guide**: `cat AMADEUS_INTEGRATION_README.md`
3. **Test again**: `./test-amadeus-complete.sh`
4. **View health**: `curl http://localhost:8081/actuator/health | jq`

---

## Ready? Let's Go! 🚀

```bash
# Step 1: Add credentials
./configure-amadeus-credentials.sh

# Step 2: Test integration
./test-amadeus-complete.sh

# Step 3: Try first booking
./first-booking-tutorial.sh
```

---

**That's it! You're ready to start booking flights with Amadeus API!** ✈️
