import { request } from '@umijs/max';

const IS_PROD = process.env.NODE_ENV === 'production' ? true : false;
export const reqBaseUrl = IS_PROD
  ? '/cd-comprehensive'
  : '';
const urlProxyApis = (url: string) => {
  return `${reqBaseUrl}${url}`;
};

/**
 * 区域和网格API服务
 */
export default {
  /**
   * 获取区域详情
   * @param regionCode 区域编码
   * @returns 返回区域详情数据
   */
  getRegionDetailByCode(regionCode: string) {
    return request(`${urlProxyApis}/grid-range/unit/${regionCode}`, {
      method: 'GET',
    });
  },

  /**
   * 获取区域大数据分析
   * @param params 查询参数
   * @returns 返回区域分析数据
   */
  getBigDataAnalysis(params: {
    regionCode: string;
    gridType?: string;
    startTime?: string;
    endTime?: string;
    dataCode?: string;
    hasChildren?: number;
  }) {
    return request(`${urlProxyApis}/api/es/v1.0/bigdata_search_analysis`, {
      method: 'POST',
      data: params,
    });
  },

  /**
   * 获取点位搜索数据
   * @param params 搜索参数
   * @returns 返回点位数据
   */
  getPointSearchData(params: {
    regionCode: string;
    dataCode?: string;
    gridtype?: string; 
    startTime?: string;
    endTime?: string;
    coordinates: string;
  }) {
    return request(`${urlProxyApis}/api/es/v1.0/search`, {
      method: 'POST',
      data: params,
    });
  }
}; 