import baseAxios from '../index'

export default class NewsService {
  static instance: NewsService
  static getInstance() {
    if (!NewsService.instance) {
      NewsService.instance = new NewsService()
    }
    return NewsService.instance
  }

  /**
   * 新增资讯
   * @param data 
   * @returns 
   */
  addArticle(data: { 
    article_type: number,
    content: string,
    desc: string,
    file_name: string,
    title: string,
    writer: string
  }) {
    return baseAxios({
      url: '/article/admin/add',
      method: 'post',
      data,
    })
  }

  /**
   * 删除新闻文章
   * @param data 
   * @returns 
   */
  delArticle(params: { uuid: string }) {
    return baseAxios({
      url: '/article/admin/delete/news',
      method: 'delete',
      params,
    })
  }

  /**
   * 删除政策文章
   * @param data 
   * @returns 
   */
  delPolicyArticle(params: { uuid: string }) {
    return baseAxios({
      url: '/article/admin/delete/policy',
      method: 'delete',
      params,
    })
  }

  /**
   * 查询列表
   * @param data 
   * @returns 
   */
  articleList(data: { 
    article_status: number|string,
    article_type: number|undefined,
    end_time: number|undefined,
    limit: number,
    offset: number,
    start_time: number|undefined
  }) {
    return baseAxios({
      url: '/article/admin/list',
      method: 'post',
      data,
    })
  }

  /**
   * 修改资讯
   * @param data 
   * @returns 
   */
  editArticle(data: {
    article_type: number,
    content: string,
    desc: string,
    file_name: string,
    title: string,
    writer: string,
    uuid: string
  }) {
    return baseAxios({
      url: '/article/admin/modify',
      method: 'post',
      data,
    })
  }

  /**
   * 修改资讯状态
   * @param data 
   * @returns 
   */
  modifyStatus(data: {
    uuid: string,
    article_status: number,
    article_type: number|undefined
  }) {
    return baseAxios({
      url: '/article/admin/modify/status',
      method: 'post',
      data,
    })
  }

  /**
   * 模糊查询新闻标题
   * @param data 
   * @returns 
   */
  searchByTitle(data: {
    title: string
  }) {
    return baseAxios({
      url: '/article/query/fuzzy/news',
      method: 'get',
      params: data,
    })
  }

  /**
   * 模糊查询政策文章
   * @param data 
   * @returns 
   */
  searchByPolicy(data: {
    title: string
  }) {
    return baseAxios({
      url: '/article/query/fuzzy/policy',
      method: 'get',
      params: data,
    })
  }

  /**
   * 查询新闻
   * @param data 
   * @returns 
   */
  searchNews(uuid: string) {
    return baseAxios({
      url: '/article/query/news',
      method: 'get',
      params: {
        uuid
      },
    })
  }

  /**
   * 查询新闻列表
   * @param data 
   * @returns 
   */
  searchList(data: {
    limit: number,
    offset: number
  }) {
    return baseAxios({
      url: '/article/query/news/list',
      method: 'post',
      data,
    })
  }

  /**
   * 查询政策文章
   * @param data 
   * @returns 
   */
  searchPolicy(uuid: string) {
    return baseAxios({
      url: '/article/query/policy',
      method: 'get',
      params: {
        uuid
      },
    })
  }

  /**
   * 查询政策列表
   * @param data 
   * @returns 
   */
  searchPolicyList(data: {
    limit: number,
    offset: number
  }) {
    return baseAxios({
      url: '/article/query/policy/list',
      method: 'post',
      data,
    })
  }


}
