from __future__ import annotations

from typing import Annotated

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.api.deps import CurrentUserContext, get_current_user, get_db
from app.schemas.notification_state import NotificationStateBatchPatch, NotificationStateListRead
from app.services.notification_states import NotificationStateService

router = APIRouter(prefix="/notification-states")
DbSession = Annotated[Session, Depends(get_db)]
CurrentUser = Annotated[CurrentUserContext, Depends(get_current_user)]


@router.get(
    "",
    response_model=NotificationStateListRead,
    summary="读取当前用户通知状态",
    description="读取当前登录用户的小铃铛通知已读和隐藏状态，用于跨设备保持一致。",
)
def list_notification_states(db: DbSession, current_user: CurrentUser) -> NotificationStateListRead:
    return NotificationStateService(db).list_states(current_user)


@router.post(
    "",
    response_model=NotificationStateListRead,
    summary="批量保存当前用户通知状态",
    description="批量保存当前登录用户的小铃铛通知已读和隐藏状态。",
)
def patch_notification_states(
    payload: NotificationStateBatchPatch,
    db: DbSession,
    current_user: CurrentUser,
) -> NotificationStateListRead:
    return NotificationStateService(db).patch_states(payload, current_user)
