import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi"; import type { CompanyAccountCreatePayload, CompanyAccountCreateResult, CompanyAccountRow, CompanyAccountUpdatePayload, } from "@/app/lib/types"; // Client over the BFF route handlers (app/api/admin/company-accounts/**), which forward the // bb_admin JWT to mobile-api. Company/HQ accounts receive referral-less registrations for a // country (prefix); create/edit/deactivate/reactivate are all mutations and always go out on // POST/PUT, never a GET (Next.js prefetch rule). /** The company accounts configured for one registration country (prefix, e.g. "MY"). */ export async function listCompanyAccounts(prefix: string): Promise { return apiGet(`/api/admin/company-accounts/${encodeURIComponent(prefix)}`); } /** Create: member + tree placement + allocation weight (+ optional login) in one action. */ export async function createCompanyAccount( payload: CompanyAccountCreatePayload, ): Promise { return apiPost("/api/admin/company-accounts", payload); } /** Edit weight/active/name. `prefix`/`memberCode` locate the row and are never themselves edited. */ export async function updateCompanyAccount( payload: CompanyAccountUpdatePayload, ): Promise { return apiPut("/api/admin/company-accounts", payload); } /** Drops the account from the weighted split; the member, its tree row and downline are untouched. */ export async function deactivateCompanyAccount(prefix: string, memberCode: string): Promise { await apiPost( `/api/admin/company-accounts/${encodeURIComponent(prefix)}/${encodeURIComponent(memberCode)}/deactivate`, ); } /** Restores the account to the weighted split. */ export async function reactivateCompanyAccount(prefix: string, memberCode: string): Promise { await apiPost( `/api/admin/company-accounts/${encodeURIComponent(prefix)}/${encodeURIComponent(memberCode)}/reactivate`, ); }