"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Measurements = void 0;
const dayjs_1 = __importDefault(require("dayjs"));
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
const codegen_1 = require("../codegen");
const base_1 = require("./base");
dayjs_1.default.extend(utc_1.default);
/**
 * We want to be flexible about the input types we accept, but we also want to
 * hit our API with a consistent response. This function takes this SDK's
 * accepted inputs for measurements and normalizes them into the Measurement
 * type.
 */
function normalizeMeasurementInput(_a) {
    var { time } = _a, rest = __rest(_a, ["time"]);
    let timestamp;
    if (time) {
        timestamp = time instanceof Date ? time : (0, dayjs_1.default)(time).utc(true).toDate();
    }
    return Object.assign({ time: timestamp }, rest);
}
class Measurements extends base_1.BaseResource {
    constructor(apiConfig) {
        super(apiConfig);
        this.api = new codegen_1.MeasurementsApi(apiConfig);
    }
    create(body, overrides) {
        if (Array.isArray(body)) {
            const measurement = body.map(normalizeMeasurementInput);
            return this.api.measurementsMultiPost({ measurement }, overrides);
        }
        const measurement = normalizeMeasurementInput(body);
        return this.api.measurementsPost({ measurement }, overrides);
    }
}
exports.Measurements = Measurements;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVhc3VyZW1lbnRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Jlc291cmNlcy9tZWFzdXJlbWVudHMudHMiXSwibmFtZXMiOltdLCJtYXB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