"""Views route registration for Lenslet."""

from __future__ import annotations

from fastapi import FastAPI

from .server_models import ViewsPayload
from .workspace import Workspace


def register_views_routes(app: FastAPI, workspace: Workspace) -> None:
    @app.get("/views", response_model=ViewsPayload)
    def get_views():
        return workspace.load_views()

    @app.put("/views", response_model=ViewsPayload)
    def put_views(body: ViewsPayload):
        payload = body.model_dump()
        workspace.save_views(payload)
        return body
