import { PunchType, TripStatus } from '../common/constants/enums';

export type TrackingLifecycleStatus =
  | 'started'
  | 'paused'
  | 'resumed'
  | 'ended';

export function mapTripStatusToTracking(
  status: TripStatus,
): TrackingLifecycleStatus {
  switch (status) {
    case TripStatus.STARTED:
    case TripStatus.TRAVELLING:
      return 'started';
    case TripStatus.ARRIVED:
    case TripStatus.MEETING_STARTED:
    case TripStatus.MEETING_COMPLETED:
      return 'paused';
    case TripStatus.RETURN_TRIP:
      return 'resumed';
    case TripStatus.COMPLETED:
    case TripStatus.CANCELLED:
      return 'ended';
    default:
      return 'ended';
  }
}

export function trackingStatusFromPunch(
  type: PunchType,
): TrackingLifecycleStatus | null {
  if (type === PunchType.DEPARTURE) return 'started';
  if (type === PunchType.ARRIVAL) return 'paused';
  return null;
}
