import 'dart:convert';

import '../../../Helper/Logger.dart';
import '../../../modules/product/product.dart';
import '../../../service/dio.dart';


class ProductsProvider {
  final CustomDio customDio = CustomDio();

  Future<ProductResponse?> getProductsBySubCategory({
    required int categoryId,
    required int tenantId, required int locationId,
  }) async {
    final url =
        "https://fiesta.nearle.app/live/api/v1/mob/products/getproductsbysubcategory?categoryid=2&tenantid=$tenantId&locationid=$locationId";
    logger.i("GET ProductsBySubCategory URL: $url");

    ProductResponse? responseModel;

    try {
      final response = await customDio.getData(url);

      if (response != null) {
        // logger.i(response);
        responseModel = ProductResponse.fromJson(response);
        // logger.i("GET Products Response: ${jsonEncode(responseModel.toJson())}");
      }
    } catch (e) {
      logger.e("Error in getProductsBySubCategory: $e");
    }

    return responseModel;
  }
}
