import httpClient from "@/services/httpClient"
import type { Response } from "@/types/response.types"
import * as urlHelper from "@/libs/url.lib"

const _prefix = "/gw/user/logo"
const _url = urlHelper.withPrefix(_prefix);

export async function upload(formData: FormData): Promise<string> {
  const resp = await httpClient.post<Response<string>>(_url(), formData)
  return resp.data.data;
}

export async function fetch(reportId: number, token: string): Promise<Blob> {
  const resp = await httpClient.get<File>(_url(`${reportId}?token=${token}`));
  return resp.data;
}

export async function remove(reportId: number) {
  const resp = await httpClient.delete<Response<boolean>>(_url(`${reportId}`));
  return resp.data.data
}

export function link(reportId: number, token: string): string {
  return `${_prefix}/${reportId}?token=${token}&t=${Date.now()}`
}
