import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';

import { ApiService } from '@services';
import { Profile } from '@models';
import { map } from 'rxjs/operators';

@Injectable({ providedIn: 'root' })
export class ProfilesService {
    private apiService = inject(ApiService);

    private _apiDomain = '/cms';

    get(username: string): Observable<Profile> {
        return this.apiService
            .get(`${this._apiDomain}/profiles/${username}`)
            .pipe(map((data: { profile: Profile }) => data.profile));
    }

    follow(username: string): Observable<Profile> {
        return this.apiService.post(`${this._apiDomain}/profiles/${username}/follow`);
    }

    unfollow(username: string): Observable<Profile> {
        return this.apiService.delete(`${this._apiDomain}/profiles/${username}/follow`);
    }
}
