/// 报告列表请求客户端

import { withPrefix } from "@/libs/url.lib";
import httpClient from "@/services/httpClient";
import type { CompanyAgg } from "@/types/company.types";
import type { ReportsResponse } from "@/types/report.types";
import type { Response } from "@/types/response.types";

const _url = withPrefix("/gw/user")

export async function query(page: number, companyIds?: number[], field?: string, keyword?: string, status?: number): Promise<ReportsResponse> {
  //const params: any = { page, companyIds, field, keyword }
  // if (companyId) {
  //   params['companyId'] = companyId;
  // }

  let param = ''
  if (companyIds && companyIds.length > 0) {
    param = companyIds.map((id: number)=>`companyIds=${id}`).join('&');
  }
  if (field && keyword && keyword.length > 0 && field.length > 0) {
    param += `&field=${field}&keyword=${keyword}`
  }
  if (status || status == 0) {
     param += `&status=${status}`
  }

  const resp = await httpClient.get<Response<ReportsResponse>>(_url(`/reports/?page=${page}&${param}`))
  return resp.data.data
}

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