/** Tenant and branch endpoints — the Nearle Admin's provisioning surface. */ import { api, WEB } from './client'; import type { TenantInfo, TenantLocation } from './types'; /** Everything the tenant-onboarding form collects. */ export interface CreateTenantRequest { tenantname: string; companyname: string; primarycontact: string; primaryemail: string; locationname: string; categoryid: number; subcategoryid?: number; address: string; suburb?: string; city: string; state: string; postcode: string; latitude?: string; longitude?: string; moduleid?: number; status?: string; } /** Everything the branch-onboarding form collects. */ export interface CreateBranchRequest { tenantid: number; locationname: string; email?: string; contactno?: string; address: string; suburb?: string; city: string; state: string; postcode: string; latitude?: string; longitude?: string; opentime?: string; closetime?: string; deliveryradius?: number; deliverymins?: number; status?: string; } export const tenantsApi = { /** * Every tenant on the platform. Deliberately unscoped — this is the * Nearle Admin's list, and the backend treats it as the platform-operator * endpoint rather than a tenant-scoped one. */ listAll: () => api.get(`${WEB}/tenants/getalltenants`), /** Branches under one tenant. `tenantid` is required — omit it and it 400s. */ locations: (tenantid: number) => api.get(`${WEB}/tenants/gettenantlocations`, { tenantid }), search: (keyword: string) => api.get(`${WEB}/tenants/searchbykeyword`, { keyword }), /** Provisions the enterprise and spawns its primary Administrator account. */ createTenant: (body: CreateTenantRequest) => api.post(`${WEB}/tenants/createtenantlocation`, body), /** Commissions a branch and spawns a placeholder branch-manager account. */ createBranch: (body: CreateBranchRequest) => api.post(`${WEB}/tenants/createlocation`, body), updateBranch: (body: Partial & { locationid: number }) => api.put(`${WEB}/tenants/updatelocation`, body), };