export const isTimeouted = (job, time = Date.now()) => {
  const duration1 = 1000 * 60 * 20; // 20 min
  const duration2 = 1000 * 60 * 60 * 4; // 4 hours

  if (job.type === 'TAGGING' || job.type === 'SCENE_RECOGNITION') {
    return time - job.updateTime > duration1;
  }

  if (job.type === 'VIDEO_ENCODING') {
    return time - job.updateTime > duration2;
  }

  if (job.type === 'VIDEO_PROCESSING' || job.type === 'VIDEO_CHILD_PROCESSING') {
    return time - job.updateTime > duration1 + duration2;
  }

  return false;
};

export const isDone = (job) => job.state === 'DONE';
export const isError = (job) => job.state === 'ERROR';
export const isFinished = (job) => isDone(job) || isError(job) || isTimeouted(job);
export const hasUnfinishedJobs = (jobs) => jobs.some((job) => !isFinished(job));
