import { Injectable } from "@angular/core";
import { jwtDecode } from 'jwt-decode';
import { BaseService } from "src/app/shared/service/base.service";

@Injectable({
    providedIn: 'root'
  })
  export class ResetPasswordService {
    constructor(private baseService:BaseService) {}
  
    decodeJwt(token: string): any {
      // Implement JWT decoding logic
      try {
        const decodedToken = jwtDecode<any>(token);
        return decodedToken;
      } catch (error) {
        console.error('Error decoding JWT token:', error);
        return null;
      }
    }
  
    getUserDetails(username: string) {
      // Assuming backend API endpoint to fetch user details by username
      return this.baseService.getData(`user/${username}`);
    }
  
    updatePassword(userId: string, newPassword: any) {
      // Assuming backend API endpoint to update user password
      const formData = new URLSearchParams();
      formData.append('password', newPassword);
      return this.baseService.putData(`user/updatePassword/${userId}`, formData);
    }
  }