import { Task } from 'apps/sales/src/app/modules/task-calendar/defs';
import { ProcessingStatus } from '@swagger/eis';

export function fromProcessStatusToTaskStatus(processingStatus: ProcessingStatus): Task['status'] {
  // tslint:disable: no-bitwise

  if (!!(processingStatus & 16)) {
    return 'Completed';
  }

  if (!!(processingStatus & 8)) {
    if (!!(processingStatus & 4)) {
      return 'Completed';
    } else if (!!(processingStatus & 2)) {
      return 'Overdue|InProgress';
    } else if (!!(processingStatus & 1)) {
      return 'Overdue|Open';
    }
  }

  if (!!(processingStatus & 4)) {
    return 'Completed';
  }

  if (!!(processingStatus & 2)) {
    return 'InProgress';
  }

  return 'Open';
}

export function fromTaskStatusToProcessingStatus(taskStatus: Task['status']) {
  switch (taskStatus) {
    case 'Open':
      return 1;
    case 'InProgress':
      return 2;
    case 'Completed':
      return 4;
    case 'Overdue|Open':
      return 4;
    case 'Overdue|InProgress':
      return 5;
    case 'Overdue':
      return 8;
    case 'Overdue|Open':
      return 9;
    case 'Overdue|InProgress':
      return 10;
  }
}
