export const QUOTATION_TOPIC_TYPE_MAPPING = {
  crane: {
    scope: 'scope_of_work',
    exclusion: 'exclusion_from_scope_of_supply',
    payment: 'terms_of_payment_upon_progress_of_each_item',
    delivery: 'delivery_date',
    warranty: 'warranty'
  },
  dockdoor: {
    scope: 'dock_scope_of_work',
    exclusion: 'exclusion_of_supply_installation',
    payment: 'payment_conditions',
    delivery: 'delivery_date',
    warranty: 'warranty'
  },
  solarcell: {
    scope: 'solarcell_scope_of_work',
    exclusion: 'solarcell_exclusion_of_supply_installation',
    payment: 'solarcell_payment_conditions',
    delivery: 'solarcell_delivery',
    warranty: 'solarcell_warranty'
  },
  default: {
    scope: 'scope_of_work',
    exclusion: 'exclusion_from_scope_of_supply',
    payment: 'payment_conditions',
    delivery: 'delivery',
    warranty: 'warranty'
  }
} as const;

function normalizeKey(value: string | null | undefined) {
  return value?.trim().toLowerCase().replaceAll(/[\s_-]+/g, '') ?? '';
}

export function getQuotationTopicMapping(quotationType?: string | null) {
  const normalized = normalizeKey(quotationType);

  if (normalized.includes('crane')) {
    return QUOTATION_TOPIC_TYPE_MAPPING.crane;
  }

  if (normalized.includes('dock')) {
    return QUOTATION_TOPIC_TYPE_MAPPING.dockdoor;
  }

  if (normalized.includes('solar')) {
    return QUOTATION_TOPIC_TYPE_MAPPING.solarcell;
  }

  return QUOTATION_TOPIC_TYPE_MAPPING.default;
}

export function resolveQuotationTopicTypeMapping(productType: string | null | undefined) {
  return getQuotationTopicMapping(productType);
}
