/** 任务进度状态 */
export enum TASK_PROCESS_STATUS {
  /** 已驳回 */
  REJECTED = '3',
  /** 未开始 */
  NO_STARTED = '1',
  /** 进行中 */
  IN_PROGRESS = '2',
  /** 已完成 */
  COMPLETED = '4',
  /** 已暂停 */
  PAUSED = '5',
  /** 已关闭 */
  CLOSED = '6',
  /** 已延期 */
  POSTPONED = '7',
}

export enum TASK_APPROVE_STATUS_ENUM {
  /**
   * 未审核
   */
  NOT_APPROVED = 0,
  /**
   * 审核中
   */
  APPROVING = 1,
  /**
   * 审核通过
   */
  APPROVED = 2,
  /**
   * 审核不通过
   */
  NOT_APPROVED_REJECT = 3,
}

export const TASK_PROCESS_STATUS_OBJ: any = {
  [TASK_PROCESS_STATUS.REJECTED]: '已驳回',
  [TASK_PROCESS_STATUS.NO_STARTED]: '未开始',
  [TASK_PROCESS_STATUS.IN_PROGRESS]: '进行中',
  [TASK_PROCESS_STATUS.COMPLETED]: '已完成',
  [TASK_PROCESS_STATUS.PAUSED]: '已暂停',
  [TASK_PROCESS_STATUS.CLOSED]: '已关闭',
  [TASK_PROCESS_STATUS.POSTPONED]: '已延期',
};

export const TASK_PROCESS_STATUS_OPTIONS = (
  Object.keys(TASK_PROCESS_STATUS_OBJ) as Array<keyof typeof TASK_PROCESS_STATUS_OBJ>
).map((key) => {
  return {
    label: TASK_PROCESS_STATUS_OBJ[key],
    value: key,
  };
});

/** 任务计算结果状态 */
export enum TASK_CALCULATE_STATUS {
  /** 未分析 */
  NO_CALCULATE = '0',
  /** 不合格 */
  UNQUALIFIED = '1',
  /** 合格 */
  QUALIFIED = '2',
  /** 临界 */
  // CRITICAL = '3',
}
export const TASK_CALCULATE_STATUS_OBJ: any = {
  [TASK_CALCULATE_STATUS.NO_CALCULATE]: '未分析',
  [TASK_CALCULATE_STATUS.QUALIFIED]: '合格',
  [TASK_CALCULATE_STATUS.UNQUALIFIED]: '不合格',
  // [TASK_CALCULATE_STATUS.CRITICAL]: '临界',
};

export const TASK_CALCULATE_STATUS_OPTIONS = (
  Object.keys(TASK_CALCULATE_STATUS_OBJ) as Array<keyof typeof TASK_CALCULATE_STATUS_OBJ>
).map((key) => {
  return {
    label: TASK_CALCULATE_STATUS_OBJ[key],
    value: key,
  };
});

export enum DEMAND_STATUS {
  /** 未确认 */
  NO_SEND = '0',
}
export const DEMAND_STATUS_MAP = {
  [DEMAND_STATUS.NO_SEND]: '未确认',
  ...TASK_PROCESS_STATUS_OBJ,
};

export const TASK_ATTENTION_STATUS = {
  /** 未关注 */
  NO_ATTENTION: 0,
  /** 已关注 */
  ATTENTION: 1,
};

/**
 * run颜色
 */
export const TasksStatusClass = {
  RUNNING: 'tag-yellow',
  CANCELING: 'tag-gray',
  CANCELED: 'tag-gray',
  FAILED: 'tag-red',
  FINISHING: 'tag-green',
  FINISHED: 'tag-green',
  QUEUED: 'tag-brown',
  PREPARE: 'tag-gray',
};
/**
 * run颜色
 */
export const TasksStatusColor = {
  RUNNING: '#b7c03e',
  CANCELING: '#888b9c',
  CANCELED: '#888b9c',
  FAILED: '#d8232a',
  FINISHING: '#1eaa39',
  FINISHED: '#1eaa39',
  QUEUED: '#f29600',
  PREPARE: '#888b9c',
};

export const disposeDisabledExeStatus = (
  status: string,
  option: { value: TASK_PROCESS_STATUS }
) => {
  if (status === TASK_PROCESS_STATUS.COMPLETED) {
    return true;
  }
  if (status === TASK_PROCESS_STATUS.IN_PROGRESS) {
    return [TASK_PROCESS_STATUS.NO_STARTED, TASK_PROCESS_STATUS.CLOSED].includes(option.value);
  }
  if (status === TASK_PROCESS_STATUS.NO_STARTED) {
    return [
      TASK_PROCESS_STATUS.PAUSED,
      TASK_PROCESS_STATUS.CLOSED,
      TASK_PROCESS_STATUS.COMPLETED,
    ].includes(option.value);
  }
  if (status === TASK_PROCESS_STATUS.PAUSED) {
    return ![TASK_PROCESS_STATUS.IN_PROGRESS].includes(option.value);
  }
  if (status === TASK_PROCESS_STATUS.REJECTED) {
    return true;
  }
};
