import 'dart:convert';

import 'package:unit2/model/profile/work_history.dart';


import 'package:http/http.dart' as http;
import 'package:unit2/utils/request.dart';

import '../../utils/urls.dart';
class WorkHistoryService{
  static final WorkHistoryService _instance = WorkHistoryService();
  static WorkHistoryService get instance => _instance;

  Future <List<WorkHistory>> getWorkExperiences( int profileId, String token)async{
      List<WorkHistory> workExperiences = [];
      String authToken = "Token $token";
                 Map<String, String> headers = {
      'Content-Type': 'application/json; charset=UTF-8',
      'Authorization': authToken
    };
    String path= Url.instance.workHistories()+profileId.toString();
    // try{
      http.Response response =await Request.instance.getRequest(path: path, headers: headers, param: {});
      if(response.statusCode == 200){
        Map data = jsonDecode(response.body);
        if(data['data'] != null){
          data['data'].forEach((var workHistory){
            workExperiences.add(WorkHistory.fromJson(workHistory));
          });
        }

      }
    // }catch(e){
    //   throw e.toString();
    // }
    return workExperiences;

  }
}