import 'package:dio/dio.dart';
import 'package:niogu_ecommerce_v1/core/constant/app_url.dart';
import 'package:niogu_ecommerce_v1/core/models/api_response_model.dart';
import 'package:niogu_ecommerce_v1/core/system/system_setting.dart';
import 'package:niogu_ecommerce_v1/features/home/data/models/home_model.dart';

abstract class ICartRemoteDatasource {
  Future<ApiResponseModel<List<ProductItemResponse>>> fetchProductBestSellers();
}

class CartRemoteDatasourceImpl implements ICartRemoteDatasource {
  final Dio _dio;

  CartRemoteDatasourceImpl(this._dio);

  @override
  Future<ApiResponseModel<List<ProductItemResponse>>>
  fetchProductBestSellers() async {
    final currentOutletId = await SystemSetting.getCurrentOutletId();

    final response = await _dio.get("${AppUrl.PRODUCTS}/best-sellers/$currentOutletId");

    return ApiResponseModel<List<ProductItemResponse>>.fromJson(
      response.data,
      (json) => (json as List)
          .map(
            (item) =>
                ProductItemResponse.fromJson(item as Map<String, dynamic>),
          )
          .toList(),
    );
  }
}
