import { Observable } from 'rxjs';

import { NativeService } from '@ucap-webmessenger/native';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';

export class BrowserNativeService implements NativeService {
  showNotify(
    roomSeq: number,
    title: string,
    contents: string,
    image: string,
    useSound: boolean
  ): void {}

  checkForUpdates(): Observable<boolean> {
    return new Observable<boolean>(subscriber => {
      try {
        subscriber.next(false);
      } catch (error) {
        subscriber.error(error);
      } finally {
        subscriber.complete();
      }
    });
  }

  showImageViewer(): void {}

  readFile(path: string): Observable<ArrayBuffer> {
    return this.httpClient.get(path, { responseType: 'arraybuffer' });
  }

  saveFile(path: string, buf: ArrayBuffer): Observable<boolean> {
    return this.httpClient.post<boolean>(path, buf, {});
  }

  constructor(private httpClient: HttpClient) {}
}
