import type { ScheduleTradeDirection } from '@edr/types';

type YardLike = { country?: string | null };

/** Derive booking/schedule trade direction from origin and destination yard countries. */
export function deriveTradeDirection(
  originYard: YardLike,
  destinationYard: YardLike,
): ScheduleTradeDirection {
  const originCountry = originYard.country?.trim();
  const destinationCountry = destinationYard.country?.trim();

  if (originCountry === 'Djibouti') {
    return 'IMPORT';
  }
  if (destinationCountry === 'Djibouti' && originCountry !== 'Djibouti') {
    return 'EXPORT';
  }
  return 'DOMESTIC';
}
