import { HttpClient } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
  EnhanceProfileRequest,
  EnhanceProfileResponse,
  FetchLinkedInProfileResponse,
  ImportLinkedInProfileRequest,
  User,
} from '../models/user.model';
import { API_URL } from '../tokens/api-url.token';

@Injectable({ providedIn: 'root' })
export class ProfileApiService {
  constructor(
    private http: HttpClient,
    @Inject(API_URL) private apiUrl: string,
  ) {}

  enhance(data: EnhanceProfileRequest): Observable<EnhanceProfileResponse> {
    return this.http.post<EnhanceProfileResponse>(`${this.apiUrl}/me/profile/enhance`, data);
  }

  fetchLinkedIn(linkedinUrl: string): Observable<FetchLinkedInProfileResponse> {
    return this.http.post<FetchLinkedInProfileResponse>(`${this.apiUrl}/me/profile/fetch-linkedin`, {
      linkedinUrl,
    });
  }

  importLinkedIn(data: ImportLinkedInProfileRequest): Observable<User> {
    return this.http.post<User>(`${this.apiUrl}/me/profile/import-linkedin`, data);
  }
}
