
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';

import '../../../Model/Request/User/Updateuser/Updateuserrequest.dart';
import '../../../Model/Response/User/Updateuser/Updateuserresponse.dart';
import '../../../Model/Response/User/Usermodelresponse.dart';



class UserProvider {
  Future<UserModelResponse?> getUser(String urldata, String token) async {
    UserModelResponse? userProfile;
    // LoginProvider();
    try {

      final url = Uri.parse('$urldata');
      final response = await http.get(url, headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'token':'$token',
        // 'Authorization': '$token',
      });
      print('userproviderresponsebody!!!!!!!!${response.body}');
      print('userproviderurldata!!!!!!!!${urldata.toString()}');
      Map<String, dynamic> parsedJson = json.decode(response.body.toString());

      userProfile = UserModelResponse.fromJson(parsedJson);

    } catch (e) {
      print(e.toString());
      print("error");
    }
    return userProfile;
  }


  Future<UserUpdateResponse?> updateUser(UserUpdateRequest data,String urldata) async {
    UserUpdateResponse? userUpdateResponse;
    // LoginProvider();
    try {

      final url = Uri.parse(urldata);

      final response = await put(url,
          body: json.encode(data),
          headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            // 'Authorization': '$token',
          });

      print('userUpdateproviderresponsebody!!!!!!!!${response.body}');
      print('userUpdateproviderurldata!!!!!!!!${urldata.toString()}');
      Map<String, dynamic> parsedJson = json.decode(response.body.toString());

      userUpdateResponse = UserUpdateResponse.fromJson(parsedJson);

    } catch (e) {
      print(e.toString());
      print("error");
    }
    return userUpdateResponse;
  }


}
