"""Example: Basic service registration with FastAPI."""

from fastapi import FastAPI
from vikdata import vikdata_service


@vikdata_service(
    name="example-service",
    service_url="http://localhost:8001",
    vikdata_url="http://localhost:8000",
    description="Example microservice",
    permissions=["example:read", "example:write"],
    enable_usage_tracking=True,
    enable_health_reporting=True,
)
def create_app() -> FastAPI:
    """Create FastAPI application with vikdata integration."""
    app = FastAPI(
        title="Example Service",
        description="Example microservice integrated with vikdata",
    )

    @app.get("/")
    async def root():
        """Root endpoint."""
        return {"message": "Example service is running"}

    @app.get("/items")
    async def list_items():
        """List items endpoint."""
        return {"items": ["item1", "item2", "item3"]}

    @app.post("/items")
    async def create_item(item: dict):
        """Create item endpoint."""
        return {"item": item, "created": True}

    # Health check is automatically added by the decorator
    # Access health checker via app.state.health_checker if needed

    return app


# Create app instance
app = create_app()


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8001)
