from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from {{ base_package }}.shared.database import get_db
from {{ base_package }}.domain.{{ table.name }}_model import {{ table.class_name }}

router = APIRouter()

# --- 3. Business Logic ---
def delete_{{ table.name }}(id: any, db: Session):
    db_obj = db.query({{ table.class_name }}).filter({{ table.class_name }}.{{ table.primary_keys[0] }} == id).first()
    if not db_obj:
        raise HTTPException(status_code=404, detail="{{ table.class_name }} not found")
    
    db.delete(db_obj)
    db.commit()
    return {"message": "{{ table.class_name }} deleted successfully"}

# --- 4. Endpoint ---
@router.delete("/{id}")
async def delete_endpoint(id: int, db: Session = Depends(get_db)):
    return delete_{{ table.name }}(id, db)
