import type { BrokerPosition } from '@/shared/api/responses'; export type BrokerPositionGroup = 'shares' | 'bonds' | 'other'; type BrokerInstrumentLinkInput = { ticker: string | null; instrumentType: string | null; classCode: string | null; }; const STOCK_CLASS_CODES = new Set(['TQBR']); const BOND_CLASS_CODES = new Set(['TQOB', 'TQCB', 'TQIR']); export function getBrokerPositionGroup( position: Pick, ): BrokerPositionGroup { const instrumentType = position.instrumentType?.toLowerCase(); if (instrumentType === 'share') return 'shares'; if (instrumentType === 'bond') return 'bonds'; return 'other'; } export function getBrokerInstrumentPath(input: BrokerInstrumentLinkInput): string | null { const ticker = input.ticker?.trim().toUpperCase(); if (!ticker) return null; const instrumentType = input.instrumentType?.toLowerCase(); const classCode = input.classCode?.toUpperCase() ?? null; if (instrumentType === 'share') { return `/stocks/${encodeURIComponent(ticker)}`; } if (instrumentType === 'bond') { return `/bonds/${encodeURIComponent(ticker)}`; } if (instrumentType) return null; if (classCode && STOCK_CLASS_CODES.has(classCode)) return `/stocks/${encodeURIComponent(ticker)}`; if (classCode && BOND_CLASS_CODES.has(classCode)) return `/bonds/${encodeURIComponent(ticker)}`; return null; }