#!/usr/bin/env python3
"""
Check restaurant data in database
"""

from sqlalchemy import create_engine, text
from urllib.parse import quote_plus

def check_data():
    DATABASE_URL = f"postgresql://postgres:{quote_plus('F@f@k0s!!')}@localhost:5432/bookbeach"
    engine = create_engine(DATABASE_URL)
    
    with engine.connect() as db:
        # Restaurant count
        result = db.execute(text('SELECT COUNT(*) FROM restaurants')).fetchone()
        print(f'Total restaurants: {result[0]}')
        
        # Menu items count
        result = db.execute(text('SELECT COUNT(*) FROM restaurant_items')).fetchone()
        print(f'Total menu items: {result[0]}')
        
        # Categories count
        result = db.execute(text('SELECT COUNT(*) FROM restaurant_categories')).fetchone()
        print(f'Total categories: {result[0]}')
        
        # Sample restaurants
        result = db.execute(text('SELECT restaurant_name, cuisine_type, description FROM restaurants LIMIT 5')).fetchall()
        print('\nSample restaurants:')
        for i, (name, cuisine, desc) in enumerate(result, 1):
            print(f'{i}. {name} - {cuisine}')
            print(f'   {desc[:80]}...')
        
        # Cuisine distribution
        result = db.execute(text('SELECT cuisine_type, COUNT(*) as count FROM restaurants GROUP BY cuisine_type ORDER BY count DESC LIMIT 10')).fetchall()
        print('\nCuisine distribution:')
        for cuisine, count in result:
            print(f'  {cuisine}: {count} restaurants')
        
        # Sample menu items
        result = db.execute(text('''
            SELECT r.restaurant_name, ri.item_name, ri.price, ri.currency_id
            FROM restaurant_items ri
            JOIN restaurants r ON ri.restaurant_id = r.restaurant_id
            LIMIT 10
        ''')).fetchall()
        print('\nSample menu items:')
        for name, item, price, currency in result:
            symbol = '€' if currency == 1 else '$'
            print(f'  {name}: {item} - {symbol}{price}')

if __name__ == '__main__':
    check_data()