package routes

import (
	"bssapp-backend/queries"
	"database/sql"
	"encoding/json"
	"fmt"
	"net/http"
)

// ✅ Handler artık parametre alıyor
func GetTodayCurrencyV3Handler(mssql *sql.DB) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		code := r.URL.Query().Get("code")
		if code == "" {
			http.Error(w, "Eksik parametre: code", http.StatusBadRequest)
			return
		}

		currency, err := queries.GetTodayCurrencyV3(mssql, code) // 👈 MSSQL
		if err != nil {
			http.Error(w, fmt.Sprintf("Kur bulunamadı: %v", err), http.StatusNotFound)
			return
		}

		w.Header().Set("Content-Type", "application/json")
		_ = json.NewEncoder(w).Encode(currency)
	}
}
