function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { request } from '@vtx/utils';
import { useRequest } from 'ahooks';
import { execute } from "../_service";
var BaseService = {
  useBaseInfo: function useBaseInfo(id) {
    var _baseInfoRes$data;
    var _useRequest = useRequest(function () {
        return request.get('/cloud/jcss-reborn/facility/get', {
          data: {
            id: id,
            coordType: 'wgs84'
          }
        });
      }, {
        ready: !!id,
        refreshDeps: [id]
      }),
      baseInfoRes = _useRequest.data;
    var _useRequest2 = useRequest(function () {
        return execute('LJFLJC_COMMUNITY_BASE_MAP', {
          id: id
        });
      }, {
        ready: !!id,
        refreshDeps: [id]
      }),
      detailRes = _useRequest2.data;
    var info = _objectSpread(_objectSpread(_objectSpread({}, baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data), baseInfoRes === null || baseInfoRes === void 0 || (_baseInfoRes$data = baseInfoRes.data) === null || _baseInfoRes$data === void 0 ? void 0 : _baseInfoRes$data.dataJson), detailRes === null || detailRes === void 0 ? void 0 : detailRes.data);
    var baseInfo = [{
      label: '分类主体类型',
      key: 'typeName',
      value: info === null || info === void 0 ? void 0 : info.typeName
    }, {
      label: '行政区划',
      key: 'divisionName',
      value: info === null || info === void 0 ? void 0 : info.divisionName
    }, {
      label: '小区类型',
      key: 'classTypeName',
      value: info === null || info === void 0 ? void 0 : info.classTypeName
    }, {
      label: '投放点数量(个)',
      key: 'throwPointNum',
      value: info === null || info === void 0 ? void 0 : info.throwPointNum
    }, {
      label: '居民户数(户)',
      key: 'householdNum',
      value: info === null || info === void 0 ? void 0 : info.householdNum
    }, {
      label: '运营单位',
      key: 'operatingUnitName',
      value: info === null || info === void 0 ? void 0 : info.operatingUnitName
    }, {
      label: '责任人',
      key: 'manageStaffName',
      value: info === null || info === void 0 ? void 0 : info.manageStaffName
    }, {
      label: '联系方式',
      key: 'manageStaffPhone',
      value: info === null || info === void 0 ? void 0 : info.manageStaffPhone
    }];
    return {
      info: info,
      baseInfo: baseInfo
    };
  },
  useDetailInfo: function useDetailInfo(code, param) {
    var _useRequest3 = useRequest(function () {
        return execute(code, _objectSpread({}, param));
      }, {
        ready: !!code,
        refreshDeps: [code, param]
      }),
      res = _useRequest3.data,
      loading = _useRequest3.loading;
    var mode = param.mode;
    var total = 0;
    var list = ((res === null || res === void 0 ? void 0 : res.data) || []).map(function (item) {
      var obj = {
        name: item.garbageTypeName,
        value: item.throwSum / (mode === 'datePicker' ? 1 : 1000),
        unit: item.unit || ''
      };
      total += item.throwSum;
      if (mode === 'datePicker') {
        obj['average'] = item.avgSum || 0;
      } else if (mode === 'monthPicker') {
        obj['tb'] = item.yearOnYear || 0;
        obj['hb'] = item.chainRatio || 0;
      } else if (mode === 'yearPicker') {
        obj['hb'] = item.chainRatio || 0;
      }
      return obj;
    });
    return {
      details: list,
      total: total,
      loading: loading
    };
  },
  useTrendInfo: function useTrendInfo(id, startDate, endDate, dateType, source) {
    var _res$data, _res$data2;
    var _useRequest4 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/throwBoard/trend', {
          data: _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, source === 'tfd' ? 'throwPointId' : 'subjectId', id), "startDate", startDate), "endDate", endDate), "filterGarbageType", true), "dateType", dateType)
        });
      }, {
        ready: !!id,
        refreshDeps: [id, startDate, endDate, dateType, source]
      }),
      res = _useRequest4.data,
      loading = _useRequest4.loading;
    var list = [];
    res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 || _res$data.forEach(function (ele) {
      var _ele$garbageValues;
      (_ele$garbageValues = ele.garbageValues) === null || _ele$garbageValues === void 0 || _ele$garbageValues.forEach(function (item, index) {
        if (Array.isArray(list[index])) {
          list[index].push(_objectSpread({}, item));
        } else {
          list[index] = [_objectSpread({}, item)];
        }
      });
    });
    return {
      trendXData: res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.map(function (ele) {
        return ele.date;
      }),
      trendData: (list === null || list === void 0 ? void 0 : list.map(function (ele) {
        return {
          name: ele[0].garbageTypeName,
          data: ele.map(function (ele) {
            return ele.value;
          })
        };
      })) || [],
      trendLoading: loading
    };
  }
};
var ThrowService = {
  useThrowConfig: function useThrowConfig() {
    var _res1$data, _res1$data2, _res1$data3;
    var _useRequest5 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/common/enumList', {
          data: {
            className: 'ThrowParamConfigEnum'
          }
        });
      }),
      res1 = _useRequest5.data;
    var params = {
      configKeys: res1 === null || res1 === void 0 || (_res1$data = res1.data) === null || _res1$data === void 0 ? void 0 : _res1$data.map(function (item) {
        return item.id;
      }).toString()
    };
    var _useRequest6 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/systemConfig/getThrowParamConfig', {
          data: _objectSpread({}, params)
        });
      }, {
        ready: !!(res1 !== null && res1 !== void 0 && (_res1$data2 = res1.data) !== null && _res1$data2 !== void 0 && _res1$data2.length),
        refreshDeps: [res1 === null || res1 === void 0 || (_res1$data3 = res1.data) === null || _res1$data3 === void 0 ? void 0 : _res1$data3.length]
      }),
      res = _useRequest6.data,
      loading = _useRequest6.loading;
    var configObj = {};
    if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && res.data) {
      for (var i = 0; i < (res === null || res === void 0 ? void 0 : res.data.length); i++) {
        var configArr = res === null || res === void 0 ? void 0 : res.data[i];
        configObj[configArr.configKey] = res === null || res === void 0 ? void 0 : res.data[i];
      }
    }
    return {
      configObj: configObj,
      loading: loading
    };
  },
  useSummaryInfo: function useSummaryInfo(id, startTime, endTime, source) {
    var _throwRes$data;
    var _useRequest7 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/trow/record/detail/throwDetailSummary', {
          data: _defineProperty(_defineProperty(_defineProperty({}, source === 'tfd' ? 'throwPointId' : 'subjectId', id), "startTime", startTime), "endTime", endTime)
        });
      }, {
        ready: !!id,
        refreshDeps: [id, startTime, endTime, source]
      }),
      throwRes = _useRequest7.data,
      loading = _useRequest7.loading;
    return {
      data: (throwRes === null || throwRes === void 0 || (_throwRes$data = throwRes.data) === null || _throwRes$data === void 0 ? void 0 : _throwRes$data.filter(function (ele) {
        return ele.garbageType !== 'CYFCL';
      })) || [],
      loading: loading
    };
  },
  usePage: function usePage(id, startTime, endTime, page, size, source) {
    var _useRequest8 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/trow/record/detail/page', {
          data: _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, source === 'tfd' ? 'throwPointId' : 'subjectId', id), "startTime", startTime), "endTime", endTime), "desensitization", true), "page", page), "size", size)
        });
      }, {
        ready: !!id,
        refreshDeps: [id, startTime, endTime, page, size]
      }),
      pageRes = _useRequest8.data,
      loading = _useRequest8.loading;
    return {
      data: pageRes === null || pageRes === void 0 ? void 0 : pageRes.data,
      loading: loading
    };
  }
};
var AlarmService = {
  useThrowConfig: function useThrowConfig() {
    var _res1$data4, _res1$data5, _res1$data6;
    var _useRequest9 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/common/enumList', {
          data: {
            className: 'ThrowParamConfigEnum'
          }
        });
      }),
      res1 = _useRequest9.data;
    var params = {
      configKeys: res1 === null || res1 === void 0 || (_res1$data4 = res1.data) === null || _res1$data4 === void 0 ? void 0 : _res1$data4.map(function (item) {
        return item.id;
      }).toString()
    };
    var _useRequest10 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/systemConfig/getThrowParamConfig', {
          data: _objectSpread({}, params)
        });
      }, {
        ready: !!(res1 !== null && res1 !== void 0 && (_res1$data5 = res1.data) !== null && _res1$data5 !== void 0 && _res1$data5.length),
        refreshDeps: [res1 === null || res1 === void 0 || (_res1$data6 = res1.data) === null || _res1$data6 === void 0 ? void 0 : _res1$data6.length]
      }),
      res = _useRequest10.data,
      loading = _useRequest10.loading;
    var configObj = {};
    if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && res.data) {
      for (var i = 0; i < (res === null || res === void 0 ? void 0 : res.data.length); i++) {
        var configArr = res === null || res === void 0 ? void 0 : res.data[i];
        configObj[configArr.configKey] = res === null || res === void 0 ? void 0 : res.data[i];
      }
    }
    return {
      configObj: configObj,
      loading: loading
    };
  },
  useSummaryInfo: function useSummaryInfo(id, startTime, endTime, source) {
    var _useRequest11 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/violation/record/detail/violationDetailSummary', {
          data: _defineProperty(_defineProperty(_defineProperty({}, source === 'tfd' ? 'throwPointId' : 'subjectId', id), "startTime", startTime), "endTime", endTime)
        });
      }, {
        ready: !!id,
        refreshDeps: [id, startTime, endTime, source]
      }),
      res = _useRequest11.data,
      loading = _useRequest11.loading;
    return {
      data: (res === null || res === void 0 ? void 0 : res.data) || {},
      loading: loading
    };
  },
  usePage: function usePage(id, startTime, endTime, page, size, source) {
    var _useRequest12 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/violation/record/detail/page', {
          data: _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, source === 'tfd' ? 'throwPointId' : 'subjectId', id), "startTime", startTime), "endTime", endTime), "desensitization", true), "page", page), "size", size)
        });
      }, {
        ready: !!id,
        refreshDeps: [id, startTime, endTime, page, size, source]
      }),
      pageRes = _useRequest12.data,
      loading = _useRequest12.loading;
    return {
      data: pageRes === null || pageRes === void 0 ? void 0 : pageRes.data,
      loading: loading
    };
  }
};
var CalendarService = {
  useCalendarInfo: function useCalendarInfo(id, startDay, endDay) {
    var areaDimension = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'COMMUNITY';
    var _useRequest13 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/trow/record/day/calendar', {
          data: {
            areaIds: id,
            areaDimension: areaDimension,
            startDay: startDay,
            endDay: endDay
          }
        });
      }, {
        ready: !!id,
        refreshDeps: [id, startDay, endDay, areaDimension]
      }),
      res = _useRequest13.data,
      loading = _useRequest13.loading;
    return {
      data: (res === null || res === void 0 ? void 0 : res.data) || {},
      loading: loading
    };
  }
};
var TfdService = {
  useSummaryInfo: function useSummaryInfo(id, dateType, startTime, endTime) {
    var _useRequest14 = useRequest(function () {
        return request.get('/cloud/ljfljc/api/v101/trow/record/detail/getThrowPointStatistics', {
          data: {
            subjectId: id,
            dateType: dateType,
            filterGarbageType: true,
            startTime: startTime,
            endTime: endTime
          }
        });
      }, {
        ready: !!id,
        refreshDeps: [id, dateType, startTime, endTime]
      }),
      res = _useRequest14.data,
      loading = _useRequest14.loading;
    return {
      data: (res === null || res === void 0 ? void 0 : res.data) || [],
      loading: loading
    };
  }
};
export { AlarmService, BaseService, CalendarService, TfdService, ThrowService };