import request from "../../../core/utils/request"; // 扫码通行api

export const getCourtlistInfoUrl = 'api/v1/proxy/intelli_court/courtList';
export const getServiceDynamicListUrl = 'api/v1/component/service/dynamic/list';
export const reportCourtInfoUrl = 'api/v1/data/template/report';
const openCardCaseUrl = '/api/v1/card/openCardCase'; // 获取小区列表(含小区列表/当前小区信息)

export async function getCourtlistInfo(data) {
  const [err, res] = await request({
    url: getCourtlistInfoUrl,
    method: 'get',
    data
  });
  if (err || !res) return [err, null];
  return [null, res];
} // 小区数据上报

export async function reportCourtInfo(data) {
  const [err, res] = await request({
    url: reportCourtInfoUrl,
    headers: {
      'content-type': 'application/json'
    },
    data
  });
  if (err || !res) return [err, null];
  return [null, res];
} // 动态数据源

export async function getServiceDynamicList(data) {
  try {
    const [err, res] = await request({
      url: getServiceDynamicListUrl,
      method: 'get',
      data: {
        componentUuid: data.componentUuid,
        current: data.current || 1,
        pageSize: data.pageSize || 10
      }
    });
    if (err) return [err, undefined]; //   return [undefined, res];
    // } catch (error) {
    //   return [error, undefined];
    // }

    return { ...res,
      index: data.index
    };
  } catch (error) {
    return {
      index: data.index,
      list: []
    };
  }
} // 是否已经开卡

export async function openCardCase(data) {
  const [err, res] = await request({
    url: openCardCaseUrl,
    headers: {
      'content-type': 'application/json'
    },
    data
  });
  if (err || !res) return [err, null];
  return [null, res];
}