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

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

/**
 * 通过报告ID获取报告数据
 * @param id 报告ID
 * @returns Promise
 */
export async function get(id: number): Promise<ReportSaveRequest> {
  const resp = await httpClient.get<Response<ReportSaveRequest>>(_url(`/${id}`))
  return resp.data.data;
}

/**
 * 请求后端服务创建一个新报告
 */
export async function create(request: ReportCreateRequest): Promise<number> {
  const resp = await httpClient.put<Response<number>>(_url(), request);
  return resp.data.data;
}

export async function save(reportSaveRequest: ReportSaveRequest) {
  const resp = await httpClient.post<Response<ReportSaveRequest>>(_url(), reportSaveRequest);
  return resp.data.data;
}

export async function updateStatus(id: number) {
  const resp = await httpClient.put<Response<number>>(_url(`/updateStatus/${id}`));
  return resp.data.data;
}

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