import 'dart:convert';

import 'package:initial_folder/base_service.dart';
import 'package:initial_folder/helper/user_info.dart';
import 'package:initial_folder/models/reset_model.dart';
import 'package:http/http.dart' as http;

class ResetService {
  Future<ResetModel> kirimEmail({
    required String email,
  }) async {
    Uri url = Uri.parse('$baseUrl/auth/web/forgot-password');
    var body = jsonEncode({
      'email': email,
    });

    print('Request URL: $url');
    print('Request Headers: $baseHeader');
    print('Request Body: $body');

    var response = await http.post(url, headers: baseHeader, body: body);
    if (response.statusCode == 200) {
       print('Berhasil kirim link reset password ke email nih :');
       print(response.statusCode);
      return ResetModel.fromJson(jsonDecode(response.body)['data']);
    } else {
      print(response.statusCode);
      print(response.request);
      print(response.reasonPhrase);
      throw Exception('Gagal Kirim Email');
      ;
    }
  }
}
