"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildQueryAndFetch = buildQueryAndFetch;
const utils_1 = require("../../utils");
const constants_1 = require("../../constants");
const fetch_1 = __importDefault(require("../fetch"));
/**
 * 拼请求参数并发请求（单次请求与单批请求共用）
 * 不处理响应转换、loading、锁、callback，由调用方负责
 */
function buildQueryAndFetch(options) {
    var _a, _b, _c;
    const { remote, innerParams, currentPage, pageSize, clearDataType, paramsData } = options;
    const paramsTransform = (0, utils_1.getTransform)((_a = remote === null || remote === void 0 ? void 0 : remote.paramsTransform) !== null && _a !== void 0 ? _a : constants_1.globalConfig === null || constants_1.globalConfig === void 0 ? void 0 : constants_1.globalConfig.defaultParamsTransform);
    const { pageSize: _ignoredPageSize, ...restParamsData } = paramsData;
    const finalQuery = paramsTransform({
        ...(0, utils_1.shouldGetDefaultParams)({
            currentPage,
            ...((innerParams === null || innerParams === void 0 ? void 0 : innerParams.current) || {}),
        }, clearDataType),
        ...((remote === null || remote === void 0 ? void 0 : remote.params) || {}),
        ...restParamsData,
        currentPage,
        pageSize,
    });
    const method = ((_b = remote === null || remote === void 0 ? void 0 : remote.method) !== null && _b !== void 0 ? _b : 'post').toLowerCase();
    const doFetch = (remote === null || remote === void 0 ? void 0 : remote.fetch) instanceof Function
        ? remote === null || remote === void 0 ? void 0 : remote.fetch(finalQuery)
        : (0, fetch_1.default)({
            url: remote === null || remote === void 0 ? void 0 : remote.url,
            method: (_c = remote === null || remote === void 0 ? void 0 : remote.method) !== null && _c !== void 0 ? _c : 'post',
            ...((remote === null || remote === void 0 ? void 0 : remote.requestOptions) || {}),
            [method === 'post' ? 'data' : 'params']: finalQuery,
        });
    return doFetch;
}
