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 
			LTRIM(RTRIM(ProductCode)) AS ProductCode
		FROM ProductFilterWithDescription('TR')
		WHERE 
			ProductAtt42 IN ('SERI', 'AKSESUAR')
			AND IsBlocked = 0
			AND LEN(LTRIM(RTRIM(ProductCode))) = 13
		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
}
