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

class AuthService {
  Future<Map<String, dynamic>?> login(Map<String, dynamic> data) async {
    try {
      final response = await commonApiService<Map<String, dynamic>>(
        url: '/api/v1/user/login/',
        method: 'POST',
        body: data,
        fromJson: (json) => json,  // Simply return the JSON map as is
      );
      return response;
    } catch (e) {
      showSnackbar(e.toString());
    }
    return null;
  }


  Future<Map<String, dynamic>?> forgotPassword(Map<String, dynamic> data) async {
    try {
      final response = await commonApiService<Map<String, dynamic>>(
        url: '/api/v1/user/password/forgot',
        method: 'POST',
        body: data,
        fromJson: (json) => json,  // Simply return the JSON map as is
      );
      return response;
    } catch (e) {
      showSnackbar(e.toString());
    }
    return null;
  }


  Future<Map<String, dynamic>?> changePassword(Map<String, dynamic> data, {required String token}) async {
    try {
      final response = await commonApiService<Map<String, dynamic>>(
        url: '/api/v1/user/password/update',
        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;
  }


}
