"""Templates for the `strura init` command."""

MAIN_PY = '''\
from contextlib import asynccontextmanager
from collections.abc import AsyncIterator

from fastapi import FastAPI


@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
    # Startup
    yield
    # Shutdown


app = FastAPI(lifespan=lifespan)


@app.get("/health")
async def health_check() -> dict[str, str]:
    return {"status": "ok"}
'''

ENV_PY = '''\
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """Application settings loaded from environment variables."""

    APP_NAME: str = "my-api"
    DEBUG: bool = False
    DATABASE_URL: str = "sqlite+aiosqlite:///./dev.db"

    model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}


settings = Settings()
'''

INIT_DB_PY = '''\
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine

# TODO: Alembic integration for migrations
from app.settings.env import settings

engine = create_async_engine(settings.DATABASE_URL, echo=settings.DEBUG)
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)


async def get_db() -> AsyncSession:  # type: ignore[misc]
    async with async_session() as session:
        yield session
'''

CONFTEST_PY = '''\
import pytest


@pytest.fixture
def app():
    """Create application fixture."""
    from app.main import app
    return app
'''
