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/features/product/data/models/product_response_model.dart';

abstract class IProductDatasourceRemote {
  Future<ApiResponseModel<ProductDetailResponse>> fetchProductById(
    String id,
  );
}

class ProductDatasourceRemoteImpl implements IProductDatasourceRemote {
  final Dio _dio;

  ProductDatasourceRemoteImpl(this._dio);

  @override
  Future<ApiResponseModel<ProductDetailResponse>> fetchProductById(
    String id,
  ) async {
    final response = await _dio.get('${AppUrl.PRODUCTS}/$id');

    return ApiResponseModel.fromJson(
      response.data,
      (json) =>
          ProductDetailResponse.fromJson(json as Map<String, dynamic>),
    );
  }
}
