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

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

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

export async function create(name: string): Promise<Company> {
  const resp = await httpClient.put<Response<Company>>(_url("/company"), { name });
  return resp.data.data;
}

export async function query(name: string, size: number = 10): Promise<Company[]> {
  const params = { name, size };
  const resp = await httpClient.get<Response<Company[]>>(_url("/company/query"), { params });
  return resp.data.data;
}

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