"""
Shortcut service routes for Memos-style backend.
"""

from typing import List

from fastapi import APIRouter, Depends, HTTPException

from common.memos_core.schemas import (
    ShortcutCreate,
    ShortcutUpdate,
    ShortcutResponse,
)
from common.memos_core.services import get_shortcut_service


router = APIRouter(prefix="/shortcuts")


@router.get("", summary="List shortcuts", response_model=List[ShortcutResponse])
async def list_shortcuts(shortcut_service=Depends(get_shortcut_service)):
    try:
        return await shortcut_service.list_shortcuts()
    except Exception as exc:  # pragma: no cover
        raise HTTPException(status_code=500, detail=str(exc)) from exc



@router.post("", summary="Create shortcut", response_model=ShortcutResponse)
async def create_shortcut(
    payload: ShortcutCreate,
    shortcut_service=Depends(get_shortcut_service),
):
    try:
        return await shortcut_service.create_shortcut(payload)
    except Exception as exc:  # pragma: no cover
        raise HTTPException(status_code=400, detail=str(exc)) from exc


@router.patch("/{shortcut_id}", summary="Update shortcut", response_model=ShortcutResponse)
async def update_shortcut(
    shortcut_id: str,
    payload: ShortcutUpdate,
    shortcut_service=Depends(get_shortcut_service),
):
    try:
        return await shortcut_service.update_shortcut(shortcut_id, payload)
    except Exception as exc:  # pragma: no cover
        raise HTTPException(status_code=400, detail=str(exc)) from exc


@router.delete("/{shortcut_id}", summary="Delete shortcut")
async def delete_shortcut(
    shortcut_id: str,
    shortcut_service=Depends(get_shortcut_service),
):
    try:
        await shortcut_service.delete_shortcut(shortcut_id)
        return {"status": "success"}
    except Exception as exc:  # pragma: no cover
        raise HTTPException(status_code=400, detail=str(exc)) from exc


