package queries

import (
	"bssapp-backend/db"
	"bssapp-backend/models"
)

// GetProductList → MSSQL'den ürün listesini döndürür
func GetProductList() ([]models.Product, error) {
	rows, err := db.MssqlDB.Query(`
		SELECT 
			ProductCode
		FROM ProductFilterWithDescription('TR')
		WHERE 
			ProductAtt42 IN ('SERI', 'AKSESUAR')
			AND IsBlocked = 0
			AND LEN(ProductCode) = 13      -- 🔹 yalnızca 13 karakterlik kodlar
		ORDER BY ProductCode;
	`)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	var list []models.Product
	for rows.Next() {
		var p models.Product
		if err := rows.Scan(&p.ProductCode); err != nil {
			return nil, err
		}
		list = append(list, p)
	}
	return list, nil
}
