# backend/app/api/v1/endpoints/services.py
from fastapi import APIRouter, Depends, Form
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import text
from app.db.session import get_db
from app.services.gamification_service import GamificationService #

router = APIRouter()

@router.post("/hunt")
async def register_service_hunt(name: str = Form(...), lat: float = Form(...), lng: float = Form(...), db: AsyncSession = Depends(get_db)):
    # Új szerviz-jelölt rögzítése a staging táblába
    await db.execute(text("""
        INSERT INTO data.service_staging (name, fingerprint, status, raw_data)
        VALUES (:n, :f, 'pending', jsonb_build_object('lat', :lat, 'lng', :lng))
    """), {"n": name, "f": f"{name}-{lat}-{lng}", "lat": lat, "lng": lng})
    
    # Jutalmazás (Hard-coded current_user_id helyett a dependency-ből kellene jönnie)
    await GamificationService.award_points(db, 1, 50, f"Service Hunt: {name}")
    await db.commit()
    return {"status": "success"}