from typing import Optional
from fastapi import APIRouter, HTTPException, Query
from app.api.course.service import CourseService
from app.api.vessel.service import VesselService

course_router = APIRouter()
vessel_service = VesselService()
service = CourseService(vessel_service=vessel_service)

@course_router.post("/sync/full_course_list")
def sync_full_course_list(vessel_id: Optional[int] = Query(None, description="Vessel ID for dynamic roles")):
    """
    Sync the full course list based on the uploaded Offline dashboard Excel
    and dynamic roles fetched from the vessel API.
    """
    if vessel_id is None:
        raise HTTPException(status_code=400, detail="vessel_id is required")

    return service.sync_full_course_list(vessel_id)
    