import * as PxTypes from '@material-hu/components/composed-components/peopleExperience/types';

import { SegmentFilter, SegmentType } from '../../../../../../types';

export const getSegmentType = (
  type: PxTypes.SegmentationGroupType,
): SegmentType => {
  if (type === PxTypes.SegmentationGroupType.AGE) {
    return SegmentType.AGE;
  }

  if (type === PxTypes.SegmentationGroupType.SENIORITY) {
    return SegmentType.SENIORITY;
  }

  return SegmentType.SEGMENTATION_GROUPS;
};

export const deriveParentIdFromSegment = (
  segmentFilter: SegmentFilter | undefined,
  parentId: number | null,
): number | null => {
  if (segmentFilter?.type === SegmentType.SEGMENTATION_GROUPS) {
    return Number(segmentFilter?.id);
  }
  if (
    [SegmentType.AGE, SegmentType.SENIORITY].includes(
      segmentFilter?.type as SegmentType,
    )
  ) {
    return null;
  }
  return parentId;
};
