import 'package:cheminova/utils/api_urls.dart';
import 'package:cheminova/utils/common_api_service.dart';
import 'package:cheminova/utils/show_snackbar.dart';


class AuthService {

  // Function to handle user login
  Future<Map<String, dynamic>?> login(Map<String, dynamic> data) async {
    try {
      // Making a POST request to the login URL using the common API service
      final response = await commonApiService<Map<String, dynamic>>(
        url: ApiUrls.loginUrl,
        method: 'POST',
        body: data,
        fromJson: (json) => json,  // Simply return the JSON map as is
      );
      return response;
    } catch (e) {
      showSnackbar(e.toString());
    }
    return null;
  }
  // Function to handle forgot password functionality  // Function to handle password change functionality
  Future<Map<String, dynamic>?> forgotPassword(Map<String, dynamic> data) async {
    try {
      // Making a POST request to the forgot password URL using the common API service
      final response = await commonApiService<Map<String, dynamic>>(
        url: ApiUrls.forgetPasswordUrl,
        method: 'POST',
        body: data,
        fromJson: (json) => json,  // Simply return the JSON map as is
      );
      return response;
    } catch (e) {
      showSnackbar(e.toString());
    }
    return null;
  }


  // Function to handle password change functionality
  Future<Map<String, dynamic>?> changePassword(Map<String, dynamic> data, {required String token}) async {
    try {
      // Making a PUT request to the change password URL using the common API service
      final response = await commonApiService<Map<String, dynamic>>(
        url: ApiUrls.changePasswordUrl,
        method: 'PUT',
        body: data,
        fromJson: (json) => json,  // Simply return the JSON map as is
        additionalHeaders: {  // Pass the token here
          'Authorization': 'Bearer $token',
        },
      );
      return response;
    } catch (e) {
      showSnackbar(e.toString());
    }
    return null;
  }


}
