"""Main app for backend api"""
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI

from .logging_config import configure_logging
from .toilets.toilets_router import router as toilets_router
from .optimization.optimization_router import router as optimization_router
from .landmarks.landmarks_router import router as landmarks_router
from .payments.payment_router import router as payment_router
from .trips.trips_router import router as trips_router


logger = logging.getLogger(__name__)


@asynccontextmanager
async def lifespan(app: FastAPI):
    """Function to run at the start of the app"""
    logger.info("Setting up logging")
    configure_logging()
    yield
    logger.info("Shutting down logging")


# Create the fastapi app
app = FastAPI(lifespan=lifespan)



# Fetches the global list of landmarks given preferences and start/end coordinates. Two routes
# Call with "/get/landmarks/" for main entry point of the trip generation pipeline.
# Call with "/get-nearby/landmarks/" for the NEARBY feature.
app.include_router(landmarks_router)


# Optimizes the trip given preferences. Second step in the main trip generation pipeline.
# Call with "/optimize/trip"
app.include_router(optimization_router)


# Fetches toilets near given coordinates.
# Call with "/get/toilets" for fetching toilets around coordinates.
app.include_router(toilets_router)


# Include the payment router for interacting with paypal sdk.
# See src/payment/payment_router.py for more information on how to call.
app.include_router(payment_router)


# Endpoint for putting together a trip, fetching landmarks by UUID and updating trip times. Three routes
# Call with "/trip/{trip_uuid}" for getting trip by UUID.
# Call with "/landmark/{landmark_uuid}" for getting landmark by UUID.
# Call with "/trip//trip/recompute-time/{trip_uuid}/{removed_landmark_uuid}" for updating trip times.
app.include_router(trips_router)
