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

const _url = urlHelper.withPrefix('/gw/user/reportTemplate')

export async function save(reportTemplateSave: ReportTemplateSave): Promise<ReportTemplateSave> {
  const resp = await httpClient.put<Response<ReportTemplateSave>>(_url(""), reportTemplateSave);
  return resp.data.data
}

export async function tags(): Promise<string[]> {
  const resp = await httpClient.get<Response<string[]>>(_url("/tags"))
  return resp.data.data
}

export async function list(field?: string, keyword?: string, page?: number): Promise<ReportTemplatesResponse> {
  const params = { field, keyword, page }
  const resp = await httpClient.get<Response<ReportTemplatesResponse>>(_url(), { params });
  return resp.data.data
}

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

export async function get(id: number): Promise<ReportTemplateSave> {
  const resp = await httpClient.get<Response<ReportTemplateSave>>(_url(id));
  return resp.data.data;
}