import type {KnownDataDetails} from 'sentry/components/events/contexts/utils';
import {t} from 'sentry/locale';
import {defined} from 'sentry/utils';

import type {OperatingSystemKnownData} from './types';
import {OperatingSystemKnownDataType} from './types';

type Props = {
  data: OperatingSystemKnownData;
  type: OperatingSystemKnownDataType;
};

export function getOperatingSystemKnownDataDetails({
  data,
  type,
}: Props): KnownDataDetails {
  switch (type) {
    case OperatingSystemKnownDataType.NAME:
      return {
        subject: t('Name'),
        value: data.name,
      };
    case OperatingSystemKnownDataType.VERSION:
      return {
        subject: t('Version'),
        value: `${data.version}${data.build ? `(${data.build})` : ''}`,
      };
    case OperatingSystemKnownDataType.KERNEL_VERSION:
      return {
        subject: t('Kernel Version'),
        value: data.kernel_version,
      };
    case OperatingSystemKnownDataType.ROOTED:
      return {
        subject: t('Rooted'),
        value: defined(data.rooted) ? (data.rooted ? t('yes') : t('no')) : null,
      };
    default:
      return undefined;
  }
}
