import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' import { Observable } from 'rxjs' import { TotpSettings, PaperlessUserProfile, SocialAccountProvider, } from '../data/user-profile' import { environment } from 'src/environments/environment' @Injectable({ providedIn: 'root', }) export class ProfileService { private endpoint = 'profile' constructor(private http: HttpClient) {} get(): Observable { return this.http.get( `${environment.apiBaseUrl}${this.endpoint}/` ) } update(profile: PaperlessUserProfile): Observable { return this.http.patch( `${environment.apiBaseUrl}${this.endpoint}/`, profile ) } generateAuthToken(): Observable { return this.http.post( `${environment.apiBaseUrl}${this.endpoint}/generate_auth_token/`, {} ) } disconnectSocialAccount(id: number): Observable { return this.http.post( `${environment.apiBaseUrl}${this.endpoint}/disconnect_social_account/`, { id: id } ) } getSocialAccountProviders(): Observable { return this.http.get( `${environment.apiBaseUrl}${this.endpoint}/social_account_providers/` ) } getTotpSettings(): Observable { return this.http.get( `${environment.apiBaseUrl}${this.endpoint}/totp/` ) } activateTotp( totpSecret: string, totpCode: string ): Observable<{ success: boolean; recovery_codes: string[] }> { return this.http.post<{ success: boolean; recovery_codes: string[] }>( `${environment.apiBaseUrl}${this.endpoint}/totp/`, { secret: totpSecret, code: totpCode, } ) } deactivateTotp(): Observable { return this.http.delete( `${environment.apiBaseUrl}${this.endpoint}/totp/`, {} ) } }