"""
Static Routes Blueprint
Contains routes for serving static files and uploads
"""
from flask import Blueprint, send_from_directory
import os

# Create Blueprint
static_bp = Blueprint('static_files', __name__)

@static_bp.route('/restaurant_photos/<path:filename>')
def serve_restaurant_photo(filename):
    """Serve restaurant photos from the restaurant_photos directory"""
    try:
        return send_from_directory('static/uploads/restaurant_photos', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/uploads/beach_photos/<filename>')
def serve_beach_photo(filename):
    """Serve beach photos from the beach_photos directory"""
    try:
        return send_from_directory('static/uploads/beach_photos', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/static/uploads/beaches/<filename>')
def serve_beaches_photo(filename):
    """Serve beach photos from the beaches directory"""
    try:
        return send_from_directory('static/uploads/beaches', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/uploads/market_items/<filename>')
def serve_market_item_photo(filename):
    """Serve market item photos from the market_items directory"""
    try:
        return send_from_directory('static/uploads/market_items', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/uploads/adventure_photos/<filename>')
def serve_adventure_photo(filename):
    """Serve adventure photos from the adventure_photos directory"""
    try:
        return send_from_directory('static/uploads/adventure_photos', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/static/uploads/markets/<filename>')
def serve_markets_photo(filename):
    """Serve market photos from the markets directory"""
    try:
        return send_from_directory('static/uploads/markets', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/static/uploads/adventures/<filename>')
def serve_adventures_photo(filename):
    """Serve adventure photos from the adventures directory"""
    try:
        return send_from_directory('static/uploads/adventures', filename)
    except FileNotFoundError:
        # Return a default image if the photo doesn't exist
        return send_from_directory('static/img', 'tour_1.jpg')

@static_bp.route('/static/uploads/restaurant_photos/<filename>')
def serve_restaurants_photo(filename):
    """Serve restaurant photos from the restaurant_photos directory"""
    try:
        # Look in the parent directory for restaurant_photos
        return send_from_directory('../restaurant_photos', filename)
    except FileNotFoundError:
        # Return 404 for missing restaurant photos
        from flask import abort
        abort(404)