import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { ApiClientService } from "../../services/api/api-client.service";
import { DataUrlFile } from "../../interfaces/image.interface";
import { ImageApiResponse } from "./image-uploader.component";


@Injectable({
  providedIn: "root",
})
export class ImageUploadService {
  constructor(private apiClient: ApiClientService) {}

  uploadImageUrl(file: string): Observable<DataUrlFile> {
    const body = {
      filename: file,
      acl: "private",
    };
    return this.apiClient.post<DataUrlFile>("file/get-upload-url", body);
  }

  uploadImageConfirm(fileUrl: string): Observable<string> {
    const body = {
      storageKey: fileUrl,
    };
    return this.apiClient.post<string>("file/confirm", body);
  }

  getImageById(id: number): Observable<ImageApiResponse> {
    return this.apiClient.get(`file/${id}/download-url`);
  }
}
