"""EX-B2-13: creation works, but the observable contract is incomplete."""

from fastapi import FastAPI
from pydantic import BaseModel, Field

app = FastAPI(title="Creation response exercise")


class RecordCreate(BaseModel):
    subject: str = Field(min_length=3)


records: dict[str, dict[str, str]] = {}


@app.post("/expedientes")
def create_record(payload: RecordCreate) -> dict[str, str]:
    record_id = f"EXP-{len(records) + 1:03d}"
    created = {"id": record_id, **payload.model_dump()}
    records[record_id] = created
    # TODO: declare public model/status and emit a coherent Location header.
    return created


@app.get("/expedientes/{record_id}")
def read_record(record_id: str) -> dict[str, str]:
    return records[record_id]
