import os
from modules.logger_tool import initialise_logger
logger = initialise_logger(__name__, os.getenv("LOG_LEVEL"), os.getenv("LOG_PATH"), 'default', True)
from fastapi import FastAPI

# Import all routers here
from routers.health import router as health_router
from routers.msgraph import router_onenote
from routers.dev.tests import timetable_test
from routers.database.init import entity_init, calendar, timetables, curriculum, get_data, schools
from routers.database.tools import get_nodes, get_nodes_and_edges, tldraw_filesystem, tldraw_supabase_storage, get_events, calendar_structure_router, default_nodes_router, worker_structure_router
from routers.database.tools.graph_tree_router import router as graph_tree_router
from routers.database.tools.user_init_router import router as user_init_router
from routers.database.tools.timetable_builder_router import router as timetable_builder_router
from routers.database.tools.school_router import router as school_router
from routers.database.tools.classes_router import router as classes_router
from routers.database.tools.taught_lessons_router import router as taught_lessons_router
from routers.database.tools.invitations_router import router as invitations_router
from routers.database.tools.platform_admin_router import router as platform_admin_router
from routers.database.tools.lesson_plans_router import router as lesson_plans_router
from routers.database.files import cabinets as cabinets_router
from routers.database.files import files as files_router
from routers.simple_upload import router as simple_upload_router
from routers.assets import powerpoint, word, pdf
from routers.llm.private.ollama import ollama
#from routers.llm.public.openai import openai
from routers.connections.arbor_router import router as arbor_router
from routers.langchain.neo4j_graph_qa import router as graph_qa_router
#from routers.langchain.interactive_langgraph_query import router as interactive_langgraph_query_router
from routers.rpi import rpi_whisperlive_client
from routers.external import youtube
from routers.solid.pod_provisioner import router as solid_pod_router
from routers.dev.document_conversion import router as document_conversion_router
from routers.dev.test_analysis import router as test_analysis_router
from routers.queue_management import router as queue_management_router
from routers.maintenance.redis_admin import router as redis_admin_router
from routers import provisioning as provisioning_router
from routers.transcribe.sessions import router as sessions_router
from routers.transcribe.canvas_events import router as canvas_events_router
from routers.transcribe.keywords import router as keywords_router

def register_routes(app: FastAPI):
    logger.info("Starting to register routes...")

    # Health check route
    app.include_router(health_router, prefix="/health", tags=["Health"])

    # Microsoft Graph Routes
    app.include_router(router_onenote.router, prefix="/msgraph", tags=["Microsoft Graph"])

    # Database Routes
    app.include_router(get_data.router, prefix="/database/upload", tags=["Upload"])
    app.include_router(get_events.router, prefix="/calendar", tags=["Calendar"])
    app.include_router(get_nodes.router, prefix="/database/tools", tags=["Tools"])
    app.include_router(get_nodes_and_edges.router, prefix="/database/tools", tags=["Tools"])
    app.include_router(entity_init.router, prefix="/database/entity", tags=["Entity"])
    app.include_router(calendar.router, prefix="/database/calendar", tags=["Calendar"])
    app.include_router(schools.router, prefix="/database/schools", tags=["Schools"])
    app.include_router(timetables.router, prefix="/database/timetables", tags=["Timetables"])
    app.include_router(curriculum.router, prefix="/database/curriculum", tags=["Curriculum"])
    
    # Navigation Routes
    app.include_router(calendar_structure_router.router, prefix="/database/calendar-structure", tags=["Calendar"])
    app.include_router(worker_structure_router.router, prefix="/database/worker-structure", tags=["Worker"])

    # Graph navigation
    app.include_router(graph_tree_router, prefix="/graph", tags=["Graph Navigation"])
    app.include_router(user_init_router, prefix="/user", tags=["User"])
    app.include_router(timetable_builder_router, prefix="/timetable", tags=["Timetable"])
    app.include_router(school_router, prefix="/school", tags=["School"])
    app.include_router(classes_router, prefix="/database/timetable/classes", tags=["Classes"])
    app.include_router(taught_lessons_router, prefix="/timetable", tags=["Taught Lessons"])
    app.include_router(invitations_router, prefix="/users", tags=["People"])
    app.include_router(platform_admin_router, prefix="/admin", tags=["Platform Admin"])
    app.include_router(lesson_plans_router, prefix="/lessons", tags=["Lesson Plans"])
    app.include_router(default_nodes_router.router, prefix="/database/tools", tags=["Navigation"])

    # Database Filesystem Routes
    app.include_router(tldraw_filesystem.router, prefix="/database/tldraw_fs", tags=["TLDraw Filesystem"])
    app.include_router(tldraw_supabase_storage.router, prefix="/database/tldraw_supabase", tags=["TLDraw Supabase Storage"])
    app.include_router(cabinets_router.router, prefix="/database", tags=["Cabinets"])
    app.include_router(files_router.router, prefix="/database", tags=["Files"])
    
    # Simple Upload Routes (no auto-processing)
    app.include_router(simple_upload_router, prefix="/simple-upload", tags=["Simple Upload"])
    
    # Assets Routes
    app.include_router(powerpoint.router, prefix="/assets/powerpoint", tags=["PowerPoint"])
    app.include_router(word.router, prefix="/assets/word", tags=["Word"])
    app.include_router(pdf.router, prefix="/assets/pdf", tags=["PDF"])

    # LLM Routes
    app.include_router(ollama.router, prefix="/llm/private/ollama", tags=["LLM"])
    #app.include_router(openai.router, prefix="/llm/public/openai", tags=["LLM"])

    # Langchain Routes
    app.include_router(graph_qa_router, prefix="/langchain/graph_qa", tags=["Langchain"])
    #app.include_router(interactive_langgraph_query_router, prefix="/langchain/interactive_langgraph_query", tags=["Langchain"])

    # External Routes
    app.include_router(youtube.router, prefix="/external", tags=["External"])

    # Arbor Data Routes
    app.include_router(arbor_router, prefix="/arbor", tags=["Arbor Data"])

    # RPi Routes
    app.include_router(rpi_whisperlive_client.router, prefix="/rpi", tags=["RPi"])

    # Solid Pod Provisioner Routes
    app.include_router(solid_pod_router, prefix="/solid", tags=["Solid"])

    # Document Conversion Routes
    app.include_router(document_conversion_router, prefix="/dev/documents", tags=["Document Conversion"])

    # Test Analysis Routes
    app.include_router(test_analysis_router, prefix="/dev/tests", tags=["Test Analysis"])

    # Queue Management Routes
    app.include_router(queue_management_router, prefix="/queue", tags=["Queue Management"])

    # Maintenance Routes
    app.include_router(redis_admin_router, prefix="/maintenance/redis", tags=["Maintenance","Redis"])

    # Provisioning Routes
    app.include_router(provisioning_router.router)

    # Transcription Routes (CIS Phase 1)
    app.include_router(sessions_router, prefix="/transcribe", tags=["Transcription Sessions"])
    app.include_router(canvas_events_router, prefix="/transcribe", tags=["Transcription Canvas Events"])
    app.include_router(keywords_router, prefix="/transcribe", tags=["Transcription Keywords"])

    # Test Routes
    app.include_router(timetable_test.router, prefix="/tests", tags=["Tests"])
