import { SectorRepository } from '@app/domain/sectors/sector.repository';
import { from, Observable } from 'rxjs';
import { environment } from '@env/environment';
import { Sector } from '@app/domain/sectors/sector.model';
import PocketBase from 'pocketbase';
import { Injectable } from '@angular/core';

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

  getOne(sectorId: string): Observable<Sector> {
    return from(this.pb.collection<Sector>('secteur').getOne<Sector>(sectorId));
  }

  list(): Observable<Sector[]> {
    return from(
      this.pb.collection<Sector>('secteur').getFullList({
        sort: 'nom',
      })
    );
  }
}
