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

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

class UserDetailRepositories {
  Dio dio = new Dio();

  final String _baseUrl = AppConst.BASE_URL;

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

    print(response.toString());
    Map<String, dynamic> data = {"data": response.data};
    return UserDetailResponse.fromJson(jsonDecode(jsonEncode(data)));
  }
}
