"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var convert_struct_to_json_exports = {};
__export(convert_struct_to_json_exports, {
  convertStructToJson: () => convertStructToJson
});
module.exports = __toCommonJS(convert_struct_to_json_exports);
var A = __toESM(require("fp-ts-esm/Array"));
var import_function = require("fp-ts-esm/function");
var import_Monoid = require("fp-ts-esm/Monoid");
var R = __toESM(require("fp-ts-esm/Record"));
var import_Semigroup = require("fp-ts-esm/Semigroup");
var T = __toESM(require("fp-ts-esm/Tuple"));
var import_fp_utils = require("../../../fp-utils.js");
var SRT = __toESM(require("../struct-refined-types.js"));
const mergeJsonMap = R.getMonoid((0, import_Semigroup.first)());
const toRecord = ([k, v]) => ({ [k]: v });
const convertStructToJson = (message) => (0, import_function.pipe)(
  message.fields,
  Object.entries,
  A.map(T.bimap(convertValueToJson, import_function.identity)),
  A.map(toRecord),
  (0, import_Monoid.concatAll)(mergeJsonMap)
);
const convertValueToJson = (message) => (0, import_fp_utils.firstRight)(message, null, [
  [SRT.isBoolValue, ({ boolValue }) => boolValue],
  [SRT.isNumberValue, ({ numberValue }) => numberValue],
  [SRT.isStringValue, ({ stringValue }) => stringValue],
  [SRT.isNullValue, () => null],
  [SRT.isArrayValue, (m) => convertListToJson(m.listValue || { values: [] })],
  [SRT.isStructValue, (m) => convertStructToJson(m.structValue || { fields: {} })]
]);
const convertListToJson = (message) => (0, import_function.pipe)(message.values, A.map(convertValueToJson));
//# sourceMappingURL=convert-struct-to-json.js.map
