import { ManualAdapter } from './manual';
import { PickupPseudoAdapter } from './pickup';
import { WoltDriveAdapter } from './wolt-drive';
import type { CarrierAdapter, CarrierKind } from './types';

type WoltDriveEnv = ConstructorParameters<typeof WoltDriveAdapter>[0];

const staticCarriers: Partial<Record<CarrierKind, CarrierAdapter>> = {
  // israel_post falls through to ManualAdapter — API not yet integrated
  israel_post: new ManualAdapter('israel_post'),
  yedioth_couriers: new ManualAdapter('yedioth_couriers'),
  cheetah: new ManualAdapter('cheetah'),
  hfd: new ManualAdapter('hfd'),
  baldar: new ManualAdapter('baldar'),
  pickup: new PickupPseudoAdapter(),
  other: new ManualAdapter('other'),
};

export function getCarrier(kind: CarrierKind, env?: WoltDriveEnv): CarrierAdapter {
  if (kind === 'wolt_drive') {
    if (!env) throw new Error('wolt_drive_requires_env');
    return new WoltDriveAdapter(env);
  }
  return staticCarriers[kind]!;
}
