import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:easycook_mobile/models/recipe_detail.dart';
import 'package:easycook_mobile/models/not_owned_ingredient.dart';
import 'package:easycook_mobile/models/owned_ingredient.dart';
import 'package:easycook_mobile/shared/shared_values.dart' as AppConst;
import 'package:shared_preferences/shared_preferences.dart';

class RecipeDetailRepositories {
  Dio dio = new Dio();

  final String _baseUrl = AppConst.BASE_URL;

  Future<RecipeDetail> getRecipeDetail(id) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var token = prefs.getString('token');
    var response = await dio.get(
      "$_baseUrl/recipes/$id/",
      options: Options(headers: {
        HttpHeaders.contentTypeHeader: 'application/json',
        HttpHeaders.authorizationHeader: 'Token $token',
      }, validateStatus: (status) => true),
    );

    return RecipeDetail.fromJson(response.data);
    // return RecipeDetail.fromJson(jsonDecode(jsonEncode(data)));
  }
}
