import http from '@/utils/http'
import type { TypicalNineCode, TypicalNineCodeParams, TypicalNineUser, TypicalNineUserParams } from '@/types/nine'
import type { TypicalFourTable, TypicalFourTags, TypicalFourUserInfo } from '@/types/four'
import type { TypicalSevenDeleteQuery, TypicalSevenQuery, TypicalSevenTable } from '@/types/seven'
import type { TypicalSixInfo, TypicalSixQueryParams } from '@/types/six'
import type { TypicalTenInfo } from '@/types/ten'
import type { PageInfo, Result, TreeInfo, TypeDescriptor } from '@cacp/ui'
import type { AxiosResponse } from 'axios'
import type { TypicalOne, TypicalOneQuery } from '@/types/one'
import type { TypicalThree, TypicalThreeList } from '@/types/three'
import type { TypicalElevenInfo, TypicalElevenThingInfo } from '@/types/eleven'
import type { EditTableUser } from '@/types/editTable'

const contextPath = '/mock'

export async function getTypicalTen() {
  const res: AxiosResponse<Result<TypicalTenInfo[]>> = await http.get(`${contextPath}/api/ten`)
  return res.data
}

export async function getTypicalSix(params: TypicalSixQueryParams) {
  const res: AxiosResponse<TypicalSixInfo> = await http.get(`${contextPath}/api/six`, {
    params
  })
  return res.data
}

export async function getTypicalFourUserinfo() {
  const res: AxiosResponse<Result<TypicalFourUserInfo>> = await http.get(`${contextPath}/api/four/userinfo`)
  return res.data
}

export async function getTypicalFourTags() {
  const res: AxiosResponse<Result<TypicalFourTags>> = await http.get(`${contextPath}/api/four/tags`)
  return res.data
}

export async function getTypicalFourTable() {
  const res: AxiosResponse<Result<TypicalFourTable[]>> = await http.get(`${contextPath}/api/four/query`)
  return res.data
}

export async function typicalFourSave(params: TypicalFourUserInfo) {
  const res: AxiosResponse = await http.post(`${contextPath}/api/four/save`, params)
  return res.data
}

export async function typicalSevenTree() {
  const res: AxiosResponse<Result<TreeInfo[]>> = await http.get(`${contextPath}/api/seven/tree`)
  return res.data
}

export async function typicalSevenQuery(params: TypicalSevenQuery) {
  const res: AxiosResponse<Result<PageInfo<TypicalSevenTable>>> = await http.get(`${contextPath}/api/seven/query`, {
    params
  })
  return res.data
}

export async function typicalSevenDelete(params: TypicalSevenDeleteQuery) {
  const res: AxiosResponse<Result<number>> = await http.get(`${contextPath}/api/seven/delete`, {
    params
  })
  return res.data
}

export async function typicalEight() {
  const res: AxiosResponse<Result<TypicalSevenTable[]>> = await http.get(`${contextPath}/api/eight`)
  return res.data
}

export async function typicalNineUser(shipId: string) {
  const res: AxiosResponse<Result<TypicalNineUser[]>> = await http.get(`${contextPath}/api/nine/user`, {
    params: {
      shipId
    }
  })
  return res.data
}

export async function typicalNineCode() {
  const res: AxiosResponse<Result<TypicalNineCode[]>> = await http.get(`${contextPath}/api/nine/code`)
  return res.data
}

export async function typicalNineUserSave(data: TypicalNineUserParams) {
  const res: AxiosResponse<Result<void>> = await http.post(`${contextPath}/api/nine/user/save`, data)
  return res.data
}

export async function typicalNineCodeSave(data: TypicalNineCodeParams) {
  const res: AxiosResponse<Result<void>> = await http.post(`${contextPath}/api/nine/code/save`, data)
  return res.data
}

export async function typicalNineUserDel(id: string | string[]) {
  const res: AxiosResponse<Result<void>> = await http.post(`${contextPath}/api/nine/user/del`, { id })
  return res.data
}

export async function typicalNineCodeDel(id: string | string[]) {
  const res: AxiosResponse<Result<void>> = await http.post(`${contextPath}/api/nine/code/del`, { id })
  return res.data
}

export async function typicalOneQuery(params: TypicalOneQuery) {
  const res: AxiosResponse<Result<PageInfo<TypicalOne>>> = await http.get(`${contextPath}/api/one`, {
    params
  })
  return res.data
}

export async function typicalThree() {
  const res: AxiosResponse<Result<TypicalThree>> = await http.get(`${contextPath}/api/three`)
  return res.data
}

export async function typicalThreeDetail(id: string) {
  const res: AxiosResponse<Result<TypicalThreeList>> = await http.get(`${contextPath}/api/three/detail`, {
    params: {
      id
    }
  })
  return res.data
}

export async function typicalEleven(params: any) {
  const res: AxiosResponse<Result<TypicalElevenInfo[]>> = await http.get(`${contextPath}/api/eleven`, {
    params
  })
  return res.data
}

export async function typicalElevenGetChild(id: string) {
  const res: AxiosResponse<Result<TypicalElevenThingInfo[]>> = await http.get(`${contextPath}/api/eleven/get/child`, {
    params: {
      id
    }
  })
  return res.data
}

export async function editTableQuery(params: any) {
  const res: AxiosResponse<Result<EditTableUser[]>> = await http.get(`${contextPath}/api/edit/table/query`, {
    params
  })
  return res.data
}

export async function editTableSave(params: any) {
  const res: AxiosResponse<Result<void>> = await http.post(`${contextPath}/api/edit/table/save`, params)
  return res.data
}

export async function editTableDelete(id: string) {
  const res: AxiosResponse<Result<void>> = await http.post(`${contextPath}/api/edit/table/delete`, { id })
  return res.data
}

export async function getAreaCodes(): Promise<Result<Array<TypeDescriptor>>> {
  const res: AxiosResponse<Result<Array<TypeDescriptor>>> = await http.get(`${contextPath}/api/areaCodes`)
  return res.data
}
