import { Injectable } from '@angular/core';
import { UserRepository } from '@app/domain/users/user.repository';
import { from, Observable } from 'rxjs';
import { environment } from '@env/environment';
import PocketBase from 'pocketbase';
import { User } from '@app/domain/users/user.model';

@Injectable({
  providedIn: 'root',
})
export class PbUserRepository implements UserRepository {
  private pb = new PocketBase(environment.baseUrl);

  getUserById(userId: string): Observable<User> {
    return from(this.pb.collection('users').getOne<User>(userId));
  }

  update(userId: string, user: Partial<User> | User): Observable<User> {
    return from(this.pb.collection('users').update<User>(userId, user));
  }
}
