import api, { unwrap } from './request';

export interface OrgNode {
  orgId: number;
  parentOrgId?: number;
  orgName: string;
  orgType: string;       // HQ / BR / TM
  orgLevel: number;
  region?: string;
  effectiveFrom?: string;
  effectiveTo?: string;
  isActive: string;
  children?: OrgNode[];
}

export const orgApi = {
  tree:   () => unwrap<OrgNode[]>(api.get('/api/orgs/tree')),
  list:   () => unwrap<OrgNode[]>(api.get('/api/orgs')),
  detail: (id: number) => unwrap<OrgNode>(api.get(`/api/orgs/${id}`)),
};
