import dayjs, { Dayjs } from 'dayjs'
import isoWeek from 'dayjs/plugin/isoWeek'
import zh from 'dayjs/locale/zh'
// import { IArticleInfoExpand } from '../Article/Article.service'
import Config from '../config'

dayjs.locale({
  ...zh,
  weekStart: 1
})

dayjs.extend(isoWeek)
// 使用传递进来的articleInfo对标题进行处理
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const titleGenerate = (articleInfo: any): string => {
  const publish_date: Dayjs = dayjs(articleInfo.publish_date)
  const generate_date =
    articleInfo.frequency === '日度'
      ? `(${publish_date.format('YY/MM/DD')})`
      : articleInfo.frequency === '周度'
      ? `(${publish_date.year()}年第${publish_date.isoWeek()}周)`
      : articleInfo.frequency === '月度'
      ? `(${publish_date.year()}年${publish_date.month() + 1}月)`
      : articleInfo.frequency === '年度'
      ? `(${publish_date.year()}年)`
      : articleInfo.frequency === '季度'
      ? publish_date.month() <= 2
        ? `(${publish_date.format('YY')}Q1)`
        : publish_date.month() <= 5
        ? `(${publish_date.format('YY')}Q2)`
        : publish_date.month() <= 8
        ? `(${publish_date.format('YY')}Q3)`
        : publish_date.month() <= 11
        ? `(${publish_date.format('YY')}Q4)`
        : ''
      : ''
  return articleInfo.type_id !== 9 && articleInfo.industry_id !== 9
    ? `【${Config.titleGenerateHz}${
        articleInfo.industry ? articleInfo.industry.name.slice(0, 2) : `${Config.titleGenerateYj}`
      }】${articleInfo.title}${generate_date}`
    : articleInfo.industry_id === 9
    ? `【弘则FICC】${articleInfo.title}${generate_date}`
    : `【Horizon Insights】${articleInfo.title}${generate_date}`
}
export default titleGenerate
