/**
 * fetchCwCompany
 *
 * Helpers for fetching ConnectWise company data via the CW REST API.
 */

import { connectWiseApi } from "../../constants";

export interface CWCompany {
  id: number;
  identifier: string;
  name: string;
  [key: string]: any;
}

/**
 * Fetch a CW company by its numeric CW company ID.
 * Returns null when not found or on API error.
 */
export async function fetchCwCompanyById(
  cwCompanyId: number
): Promise<CWCompany | null> {
  try {
    const response = await connectWiseApi.get<CWCompany>(
      `/company/companies/${cwCompanyId}`
    );
    return response.data ?? null;
  } catch {
    return null;
  }
}
