"""Erinnerungen & Routinen (A3) — dünner REST-Layer über services/reminders.py.
Konsument ist v.a. der Hermes-Agent via mcp_mc.py (reminder_create/list/delete);
LAN-only wie alle MC2-Endpoints."""

from fastapi import APIRouter, HTTPException
from pydantic import BaseModel

from services import reminders

router = APIRouter(prefix="/api")


class ReminderIn(BaseModel):
    text: str          # was angesagt werden soll
    when: str          # ISO-8601; ohne Offset = Commander-Zeitzone (Europe/Berlin)
    repeat: str = ""   # '' einmalig | daily | weekdays | weekly


@router.get("/reminders")
def list_reminders() -> dict:
    return {"items": reminders.list_all()}


@router.post("/reminders")
def create_reminder(body: ReminderIn) -> dict:
    try:
        return {"ok": True, "item": reminders.create(body.text, body.when, body.repeat)}
    except ValueError as exc:
        raise HTTPException(400, str(exc))


@router.delete("/reminders/{reminder_id}")
def delete_reminder(reminder_id: int) -> dict:
    try:
        return {"ok": True, "deleted": reminders.delete(reminder_id)}
    except KeyError as exc:
        raise HTTPException(404, str(exc.args[0]))
