import { fromProcessStatusToTaskStatus } from './task-status.mapper';
import { taskTypeMapper } from './task-type-mapper';
import { fromTimeToTimeWindow } from './time-window.mapper';
import { taskIsAllDay, taskIsMultiDay } from './task-duration.mapper';
import { DisplayInfoDTO } from '@swagger/eis';
import { Task } from 'apps/sales/src/app/modules/task-calendar/defs';

export function fromDisplayInfoToTask(source: DisplayInfoDTO): Task {
  return {
    id: source.id,
    status: fromProcessStatusToTaskStatus(source.processingStatus),
    title: source.title,
    body: source.text,
    category: source.category,
    type: taskTypeMapper(source.hasTask, {
      publicationDate: source.publicationDate,
      taskDate: source.taskDate,
    }),
    date: new Date(source.timeFrom || source.taskDate || source.publicationDate),
    timeWindow: fromTimeToTimeWindow(source.timeFrom, source.timeTo),
    isAllDay: taskIsAllDay(source.timeFrom, source.timeTo),
    isMultiDay: taskIsMultiDay(source.timeFrom, source.timeTo),
    requiresImageOnConfirmation: source.requiresImageOnConfirmation,
    hasArticles: !!source.articles && !!source.articles.length,
    hasAttachments: !!source.attachments,
    hasTeaserImages: !!source.images && !!source.images.length,
  };
}
