/**
 * 烈士-列表
 */

import http from '@/utils/http'
import { AppDispatch } from '@/store'
import { MartyrItem } from '@/types/api/martyr'

/**
 * 获取烈士列表
 */
type Martyr_APIgetListParams = {
  display: number
}
export const Martyr_APIgetList = (data: Martyr_APIgetListParams): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get('show/martyr/getList', { params: data })
    if (res.code === 0) {
      console.log(res.data.length, 'res.data')
      const cityMap: Record<string, string> = {
        东营市: 'tap-dongying',
        济南市: 'tap-jinan',
        青岛市: 'tap-qingdao',
        淄博市: 'tap-zibo',
        潍坊市: 'tap-weifang',
        烟台市: 'tap-yantai',
        威海市: 'tap-weihai',
        日照市: 'tap-rizhao',
        临沂市: 'tap-linyi',
        枣庄市: 'tap-zaozhuang',
        聊城市: 'tap-liaocheng',
        滨州市: 'tap-binzhou',
        菏泽市: 'tap-heze',
        德州市: 'tap-dezhou',
        泰安市: 'tap-taian',
        济宁市: 'tap-jining'
      }
      const obj = {
        list: res.data.map((item: MartyrItem) => ({
          ...item,
          gender: item.gender === 1 ? '男' : '女',
          cityId: cityMap[item.nativeCity] || ''
        })),
        total: res.data.total
      }

      dispatch({ type: 'Martyr_APIgetList', payload: obj })
    }
  }
}

/**
 * 根据省份获取亲属列表
 */
type Martyr_APIgetRelativeListParams = {
  nativeProvince: string
}
export const Martyr_APIgetRelativeList = (data: Martyr_APIgetRelativeListParams): any => {
  return http.get('show/kinship/findByProvince', { params: data })
}

/**
 * 根据省份获取线索列表
 */
type Martyr_APIgetClueListParams = {
  nativeProvince: string
}
export const Martyr_APIgetClueList = (data: Martyr_APIgetClueListParams): any => {
  return http.get('show/clue/findByProvince', { params: data })
}

/**
 * 获取烈士详情
 */
type Martyr_APIgetDetailParams = {
  id: number
}
export const Martyr_APIgetDetail = (data: Martyr_APIgetDetailParams): any => {
  return http.get(`show/martyr/detail/${data.id}`)
}

/**
 * 获取人物关系
 */
type Martyr_APIgetRelationListParams = {
  martyrId: number
}
export const Martyr_APIgetRelationList = (data: Martyr_APIgetRelationListParams): any => {
  return http.get(`show/relation/${data.martyrId}`)
}
