# Generated by @docstream/fastapi-server-emitter
# Do not edit this file manually — regenerate with: tsp compile .
# This file contains FastAPI router definitions generated from TypeSpec.
"""FastAPI router generated from TypeSpec operations."""
from __future__ import annotations


from fastapi import APIRouter, Depends, HTTPException, Path, Query, status
from pydantic import BaseModel

from ..models.contexts import Context, ContextCreate, ContextList, ContextUpdate, Source, SourceCreate, SourceList
from ..models.errors import NotFoundError, ValidationError


router = APIRouter(tags=["Contexts"])


@router.post("/api/v1/contexts/", response_model=ValidationError)
async def create_context(body: ContextCreate) -> ValidationError:
    """Create a context — Create a new context with an optional renderer default and initial sources."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint POST /api/v1/contexts/ not yet implemented"
    )


@router.get("/api/v1/contexts/", response_model=ContextList)
async def list_contexts() -> ContextList:
    """List contexts — List all contexts and their sources."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint GET /api/v1/contexts/ not yet implemented"
    )


@router.get("/api/v1/contexts/{id}", response_model=NotFoundError)
async def get_context(id: str = Path(..., description="Context id (URL-safe slug).")) -> NotFoundError:
    """Get a context — Get a single context by id."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint GET /api/v1/contexts/{id} not yet implemented"
    )


@router.patch("/api/v1/contexts/{id}", response_model=NotFoundError)
async def update_context(id: str, body: ContextUpdate) -> NotFoundError:
    """Update a context's renderer — Update the context-level renderer default. The `id` and `sources` fields are not writable via PATCH."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint PATCH /api/v1/contexts/{id} not yet implemented"
    )


@router.delete("/api/v1/contexts/{id}", response_model=NotFoundError)
async def delete_context(id: str) -> NotFoundError:
    """Delete a context — Delete a context. Idempotent: deleting a missing context returns 204."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint DELETE /api/v1/contexts/{id} not yet implemented"
    )


@router.post("/api/v1/contexts/{id}/sources", response_model=NotFoundError)
async def add_source(id: str, body: SourceCreate) -> NotFoundError:
    """Add a source to a context — Add a source to a context. The server derives `slug` and rejects 409 if it collides."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint POST /api/v1/contexts/{id}/sources not yet implemented"
    )


@router.get("/api/v1/contexts/{id}/sources", response_model=NotFoundError)
async def list_sources(id: str) -> NotFoundError:
    """List sources in a context — List all sources belonging to a context."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint GET /api/v1/contexts/{id}/sources not yet implemented"
    )


@router.get("/api/v1/contexts/{id}/sources/{slug}", response_model=NotFoundError)
async def get_source(id: str, slug: str) -> NotFoundError:
    """Get a source — Get a single source by slug within a context."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint GET /api/v1/contexts/{id}/sources/{slug} not yet implemented"
    )


@router.delete("/api/v1/contexts/{id}/sources/{slug}", response_model=NotFoundError)
async def delete_source(id: str, slug: str) -> NotFoundError:
    """Remove a source — Remove a source from a context. Idempotent: removing a missing source returns 204."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint DELETE /api/v1/contexts/{id}/sources/{slug} not yet implemented"
    )


@router.post("/api/v1/contexts/{id}/reload", response_model=NotFoundError)
async def reload_context(id: str) -> NotFoundError:
    """Force a context reload — Invalidate render caches for a context; the config watcher reconciles watchers."""
    # TODO: Implement business logic (Phase 3 — service layer)
    raise NotImplementedError(
        "Endpoint POST /api/v1/contexts/{id}/reload not yet implemented"
    )
