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

const _prefix = "/gw/user/reportTemplate/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(templateId: number, token: string): Promise<Blob> {
  const resp = await httpClient.get<File>(_url(`${templateId}?token=${token}`));
  return resp.data;
}

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

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