import 'package:dio/dio.dart';
import 'package:food_health/api/dto/food_scan_dto.dart';

import '../network/request.dart';

///食物检测
Future<FoodScanDto> foodScanApi(List<int> bytes) async {
  FormData formData = FormData.fromMap({
    "food_image": MultipartFile.fromBytes(
      bytes,
      filename: "upload.jpg",
      contentType: DioMediaType("image", "jpeg"),
    ),
  });
  var res = await Request().post("/food/scan", formData);
  return FoodScanDto.fromJson(res);
}

///食物检测列表
Future<List<FoodScanDto>> foodScanListApi() async {
  var res = await Request().get("/food/records");
  return res['list'].map<FoodScanDto>((e) => FoodScanDto.fromJson(e)).toList();
}
