import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart';

class ProductApi {
  Future<List<ProductModel>> fetchProducts() async {
    try {
      final response = await HTTPService().get(
        path: ApiEndpoints.listProducts,
        expectedResponseModel: (json) {
          List<dynamic> jsonData = json['data'];

          List<ProductModel> productList = jsonData.map((jsonItem) {
            return ProductModel.fromMap(jsonItem);
          }).toList();
          return productList;
        },
      );
      return response;
    } catch (e) {
      debugPrint('Error fetching products: $e');
      return [];
    }
  }
}
