from typing import Annotated, List, Optional
from uuid import UUID

from fastapi import APIRouter, Depends, HTTPException, Query, status

from src.auth.service import CurrentUser
from src.dashboard_model.schema import DashboardModelQuery
from src.database.core import DbSession
from src.database.service import CommonParameters
from src.models import StandardResponse
from src.dashboard_model.schema_masterdata import RBDMasterDataSchema, RBDMasterDataUpdate

from .service import get_model_data

router = APIRouter()


@router.get("", response_model=StandardResponse[dict])
async def get_dashboard_model_data(
    db_session: DbSession,
    query:Annotated[DashboardModelQuery, Query()]
):
    simulation_id = query.simulation_id
    result = await get_model_data(db_session=db_session, simulation_id=simulation_id)

    return StandardResponse(
        data=result,
        message="Data retrieved successfully",
    )


@router.get("/master-data", response_model=StandardResponse[List[RBDMasterDataSchema]])
async def get_dashboard_master_data(
    db_session: DbSession
):
    from src.dashboard_model.service import get_master_data_list
    result = await get_master_data_list(db_session=db_session)

    
    return StandardResponse(
        data=result,
        message="Master data retrieved successfully"
    )


@router.post("/master-data/{md_id}/update", response_model=StandardResponse[RBDMasterDataSchema])
async def update_dashboard_master_data(
    md_id: UUID,
    payload: RBDMasterDataUpdate,
    db_session: DbSession
):
    from src.dashboard_model.service import update_master_data
    result = await update_master_data(db_session=db_session, md_id=md_id, payload=payload)
    return StandardResponse(
        data=result,
        message="Master data updated successfully"
    )
