{"version":3,"file":"extractReferenceLocation.mjs","names":[],"sources":["../../src/utils/extractReferenceLocation.ts"],"sourcesContent":["import type {\n  ReferenceLocation,\n  WithReferenceLocationOnPrefixOptional,\n  WithReferenceLocationOnPrefix,\n} from '../Airspace/types.js';\n\nconst keys = [\n  'ReferenceLocationAirspace',\n  'ReferenceLocationAerodrome',\n  'ReferenceLocationAerodromeSet',\n  'ReferenceLocationDbePoint',\n  'ReferenceLocationPublishedPoint',\n] as const;\n\n/**\n * Extract a reference location with a given key-prefix from a reply object.\n * @param prefix Prefix of the keys of the reference location\n * @param input NMB2B object\n *\n *\n * @example\n * ```typescript\n * const input = {\n *   'protectedLocation-ReferenceLocationAirspace': { type: 'AIRSPACE', id: 'LFEEKR' },\n *   regulationId: 'FOOBAR',\n * };\n *\n * const location = extractReferenceLocation('protectedLocation', input);\n * // { type: 'AIRSPACE', id: 'LFEEKR' }\n * ```\n */\nexport function extractReferenceLocation<\n  const TPrefix extends string,\n  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters\n  TInput extends WithReferenceLocationOnPrefix<TPrefix>,\n>(prefix: TPrefix, input: TInput): ReferenceLocation;\n\n/**\n * Extract a reference location with a given key-prefix from a reply object.\n * @param prefix Prefix of the keys of the reference location\n * @param input NMB2B object\n *\n *\n * @example\n * ```typescript\n * const input = {\n *   'protectedLocation-ReferenceLocationAirspace': { type: 'AIRSPACE', id: 'LFEEKR' },\n *   regulationId: 'FOOBAR',\n * };\n *\n * const location = extractReferenceLocation('protectedLocation', input);\n * // { type: 'AIRSPACE', id: 'LFEEKR' }\n * ```\n */\nexport function extractReferenceLocation<\n  const TPrefix extends string,\n  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters\n  TInput extends undefined | WithReferenceLocationOnPrefixOptional<TPrefix>,\n>(prefix: TPrefix, input: TInput): undefined | ReferenceLocation;\n\nexport function extractReferenceLocation<\n  const TPrefix extends string,\n  TInput extends\n    | undefined\n    | WithReferenceLocationOnPrefixOptional<TPrefix>\n    | WithReferenceLocationOnPrefix<TPrefix>,\n>(prefix: TPrefix, input: TInput): ReferenceLocation | undefined {\n  if (!input) {\n    return;\n  }\n\n  for (const k of keys) {\n    const key = `${prefix}-${k}` as const;\n\n    if (key in input) {\n      return input[key as keyof TInput];\n    }\n  }\n}\n"],"mappings":";AAMA,MAAM,OAAO;CACX;CACA;CACA;CACA;CACA;CACD;AAgDD,SAAgB,yBAMd,QAAiB,OAA8C;AAC/D,KAAI,CAAC,MACH;AAGF,MAAK,MAAM,KAAK,MAAM;EACpB,MAAM,MAAM,GAAG,OAAO,GAAG;AAEzB,MAAI,OAAO,MACT,QAAO,MAAM"}