import urllib.request
import json

base = 'http://localhost:8080/api/v1'

def check_get(endpoint):
    with urllib.request.urlopen(f'{base}/{endpoint}') as resp:
        data = json.loads(resp.read().decode('utf-8'))
        count = len(data) if isinstance(data, list) else "OK"
        print(f"GET /{endpoint} -> Status: {resp.status}, count: {count}")

check_get('vehicles')
check_get('locations')
check_get('activities')
check_get('accommodations')
check_get('company/profile')
check_get('company/services')

# Test quote
quote_req = urllib.request.Request(
    f'{base}/bookings/calculate-quote',
    headers={'Content-Type': 'application/json'},
    data=json.dumps({
        'vehicleUuid': '5da09089-863a-46d1-b92e-20f5a24d2200',
        'pickupDate': '2026-11-01',
        'dropoffDate': '2026-11-05',
        'insuranceTier': 'PREMIUM',
        'childSeat': True
    }).encode('utf-8')
)
with urllib.request.urlopen(quote_req) as resp:
    data = json.loads(resp.read().decode('utf-8'))
    print(f"POST /bookings/calculate-quote -> {data['days']} days, total: ${data['estimatedTotal']} USD")

# Test booking
booking_req = urllib.request.Request(
    f'{base}/bookings',
    headers={'Content-Type': 'application/json'},
    data=json.dumps({
        'vehicleUuid': '5da09089-863a-46d1-b92e-20f5a24d2200',
        'pricingUuid': '03fddaed-39a9-457f-998f-fa1665867717',
        'pickupLocationUuid': '809d4417-8933-44e1-91d8-0474028c14be',
        'dropoffLocationUuid': '809d4417-8933-44e1-91d8-0474028c14be',
        'pickupDate': '2026-11-01',
        'dropoffDate': '2026-11-05',
        'pickupTime': '09:00',
        'dropoffTime': '17:00',
        'purpose': 'Victoria Falls Safari Holiday',
        'clientName': 'Tendai Moyo',
        'clientPhoneNumber': '+263771234567',
        'clientEmailAddress': 'tendai@example.com',
        'insuranceCoverageTier': 'COMPREHENSIVE_PREMIUM',
        'childSeat': True
    }).encode('utf-8')
)
with urllib.request.urlopen(booking_req) as resp:
    data = json.loads(resp.read().decode('utf-8'))
    print(f"POST /bookings -> Confirmed! Ref: {data['bookingReference']}, Total: ${data['grandTotal']} USD, CentricGo URL: {data['directCentricGoBookingUrl']}")

# Check frontend root
with urllib.request.urlopen('http://localhost:5173/') as resp:
    html = resp.read().decode('utf-8')
    print(f"GET http://localhost:5173/ -> Status: {resp.status}, Title present: {'Tesco Rise' in html}")
