import request from "@/api/request.js";
import {
    ElMessage
} from 'element-plus'

const request200 = (requestP) => {
    return requestP.then((data) => {
        if (data.code === 200) {
            return data.data
        }
        ElMessage({
            message: data.message,
            type: 'error',
            duration: 3 * 1000
        })
        return {}
    })
}

// 实体清单总条数统计
/**
 * @returns {Promise<number>} 
 */
export function getEntitiesDataCount() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countData',
    }))
}

// 最新实体清单信息查询
/**
 * @returns {Promise<{
 * chNum: number
 * entities:{
 *  entityNameZh: string
 *  entityName: string
 * }[]
 * organization:{
 *  orgName: string
 * }
 * domains: string[]
 * startTime: string
 *}>} 
 */
export function getEntitiesDataInfo() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataInfo/latestInfoSelect',
    }))
}

/**
 * 每年最多领域及该领域发布次数
 * @returns {Promise<{
 * year?: number
 * maxDomain: string
 * maxCount: number
 * }[]>}
 */
export function getIndustryCountByYear() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/industryCountByYear',
    }))
}

/**
 * 不同领域每年数量
 * @returns {Promise<{
 * data:{
 *   year?: number
 *   domainNum: {
 *    [ key: string]: number;
 *   }
 * }[]
 * domains: string[]
 * }>}
 */
export function getCountDomainByYear() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countDomainByYear',
    }))
}

/**
 * 历次制裁过程（月份统计）
 * @returns {Promise<{
 * tittle: string
 * entitiesChNum: string
 * sanReason: string
 * }[]>}
 */
export function getSanctionsInfoCount() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/sanctionsInfoCount',
    }))
}

/**
 * 查询发布机构
 * @returns {Promise<{
 * orgName: string         //机构名称
 * orgIntroduction: string //相关措施
 * orgIntroduction: string //机构职责
 * }>}
 */
export function getOrganizationInfo() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataInfo/getOrganizationInfo',
    }))
}

/**
 * 查询重点人物
 * @returns {Promise<{
 * name: string
 * ename: string
 * avatarUrl: string
 * positionTitle: string
 * }[]>}
 */
export function getPersonList() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataInfo/getPersonList',
    }))
}

/**
 * 不同领域实体统计
 * @param {string} startTime - 统计开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<{
 * domain: string
 * count: number
 * }[]>}
 */
export function getCountByDomain(startTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countByDomain',
        params: {
            startTime
        }
    }))
}

/**
 * 不同类型实体统计
 * @param {string} startTime - 统计开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<{
 * type: string
 * count: number
 * }[]>}
 */
export function getCountByType(startTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countByType',
        params: {
            startTime
        }
    }))
}

/**
 * 查询制裁原因
 * @param {string} startTime - 统计开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<string[]>}
 */
export function getSanReasonSelect(startTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataInfo/sanReasonSelect',
        params: {
            startTime
        }
    }))
}

/**
 * 查询实体清单列表
 * @param {string} startTime - 统计开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<{
 * entityNameZh: string
 * techDomainList: string[]
 * startTime: staring
 * }[]>}
 */
export function getSelectEntitiesList(startTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataInfo/selectEntitiesList',
        params: {
            startTime
        }
    }))
}

/**
 * 数量比对分析
 * @param {string} startTime - 统计开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<{
 * countDomainLast: number
 * countDomainNow: number
 * countSanLast: number
 * countSanNow: number
 * countTypeLast: number
 * countTypeNow: number
 * }>}
 */
export function getCompareCountSan(startTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/compareCountSan',
        params: {
            startTime
        }
    }))
}

/**
 * 实体清单变化统计
 * @param {number} domain 
 * @param {number} type 
 * @returns {Promise<{
 * year:number
 * count:number
 * }[]>}
 */
export function getEntitiesChangeCount(domain, type) {
    return request200(request({
        method: 'GET',
        // url: '/api/entitiesDataCount/entitiesChangeCount',
        url: '/api/entitiesDataCount/sanCountByYear',
        params: {
            domain,
            type
        }
    }))
}

/**
 * 新增实体数量增长趋势
 * @returns {Promise<{
 * year: string
 * percent: string //百分比'20%'
 * }>}
 */
export function getEntitiesGrowthTrend() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/entitiesGrowthTrend',
    }))
}

/**
 * 实体清单更新频率
 * @returns {Promise<{
 * series: number[]
 * xAxis: string[]
 * }>}
 */
export function getEntitiesUpdateCount() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/entitiesUpdateCount',
    }))
}

/**
 * 新增实体领域分布情况
 * @param {string} sanTime - 开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<{
 * value: number
 * name: string
 * }[]>}
 */
export function getEntitiesAreaCountByYear(sanTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/entitiesAreaCountByYear',
        params: {
            sanTime
        }
    }))
}

/**
 * 历次制裁涉及领域数
 * @returns {Promise<{
 * series: number[]
 * xAxis: string[]
 * }>}
 */
export function getEntitiesDomainCount() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/entitiesDomainCount'
    }))
}

/**
 * 指定领域每年实体数量查询
 * @param {string} param 
 * @returns {Promise<{
 * year: string
 * count: number
 * }[]>}
 */
export function getCountThisDomain(param) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countThisDomain',
        params: {
            param
        }
    }))
}

/**
 * 历次制裁涉及类别数量
 * @returns {Promise<{
 * year: string
 * count: number
 * }[]>}
 */
export function getCountTypeByYear() {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countTypeByYear',
    }))
}

/**
 * 新增实体类别统计
 * @param {string} startTime - 开始时间，格式为 'YYYY-MM-DD'
 * @returns {Promise<{
 * type: string
 * count: number
 * }[]>}
 */
export function getCountSanTypeByTime(startTime) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countSanTypeByTime',
        params: {
            startTime
        }
    }))
}

/**
 * 指定类别每年实体数量查询
 * @param {string} param 
 * @returns {Promise<{
 * year: number
 * count: number
 * }[]>}
 */
export function getCountThisType(param) {
    return request200(request({
        method: 'GET',
        url: '/api/entitiesDataCount/countThisType',
        params: {
            param
        }
    }))
}

