import { normalizeRegionCode, normalizeRegionParentCode, normalizeRegionSelectorItems } from './region-contract.js' import { createRequestError, requestStrict } from './request-client.js' export const regionApi = { async getRegionChildren(parentCode, requestOptions = {}) { const regionChildren = await requestStrict({ url: '/genealogy/app/region/children', method: 'GET', data: { parentCode: normalizeRegionParentCode(parentCode) } }, { requestController: requestOptions.requestController ?? null }) return normalizeRegionSelectorItems(regionChildren) }, async getRegionPath(regionCode, requestOptions = {}) { const regionPath = await requestStrict({ url: `/genealogy/app/region/path/${encodeURIComponent(normalizeRegionCode(regionCode))}`, method: 'GET' }, { requestController: requestOptions.requestController ?? null }) if (!Array.isArray(regionPath)) { throw createRequestError('行政区划路径响应不是列表', 'REGION_PATH_RESPONSE_INVALID') } return regionPath } }