

import 'dart:convert';

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

import '../model/profile/other_information/skills_and_hobbies.dart';
import '../utils/urls.dart';
import 'package:http/http.dart' as http;
class SkillsHobbiesServices{
  static final SkillsHobbiesServices _instance = SkillsHobbiesServices();
  static SkillsHobbiesServices get instance => _instance;

  Future<List<SkillsHobbies>> getSkillsHobbies(int profileId, String token)async{

     List<SkillsHobbies> skillsAndHobbies = [];
     String authToken = "Token $token";
    String path = "${Url.instance.getSkillsHobbies()}$profileId/";
    Map<String, String> headers = {
      'Content-Type': 'application/json; charset=UTF-8',
      'Authorization': authToken
    };
  try{
    http.Response response = await Request.instance.getRequest(path: path,param: {},headers: headers);
    if(response.statusCode == 200){
      Map data = jsonDecode(response.body);
      if(data['data']['skill_hobby'] != null){
        data['data']['skill_hobby'].forEach((var hobby){
          SkillsHobbies skillsHobby = SkillsHobbies.fromJson(hobby);
          skillsAndHobbies.add(skillsHobby);
        });
      }
    }
  }catch(e){
    throw e.toString();
  }
  return skillsAndHobbies;
  }
}

