from fastapi import APIRouter, Depends
from pydantic import BaseModel
from sqlalchemy.orm import Session
from typing import List
from datetime import datetime
from {{ base_package }}.shared.database import get_db
from {{ base_package }}.domain.{{ table.name }}_model import {{ table.class_name }}

router = APIRouter()

# --- 2. Response DTO ---
class {{ table.class_name }}Response(BaseModel):
    {% for col in table.columns -%}
    {{ col.name }}: {{ col.python_type }}{% if col.nullable %} = None{% endif %}
    {% endfor %}
    
    class Config:
        from_attributes = True

# --- 3. Business Logic ---
def get_{{ table.name }}_list(db: Session, skip: int = 0, limit: int = 100) -> List[{{ table.class_name }}]:
    return db.query({{ table.class_name }}).offset(skip).limit(limit).all()

# --- 4. Endpoint ---
@router.get("/", response_model=List[{{ table.class_name }}Response])
async def get_list_endpoint(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
    return get_{{ table.name }}_list(db, skip=skip, limit=limit)
