"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_json_to_struct_exports = {};
__export(convert_json_to_struct_exports, {
  convertJsonToStruct: () => convertJsonToStruct
});
module.exports = __toCommonJS(convert_json_to_struct_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_lodash = __toESM(require("lodash"));
var import_v1 = require("./../../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_fp_utils = require("../../../fp-utils.js");
const valueM = R.getMonoid((0, import_Semigroup.first)());
const toRecord = ([k, v]) => ({ [k]: v });
const toStruct = (fields) => ({ fields });
const toListValue = (values) => ({ values });
const defaultValue = {
  numberValue: void 0,
  nullValue: void 0,
  stringValue: void 0,
  boolValue: void 0
};
const convertJsonToList = (json) => (0, import_function.pipe)(json, A.map(convertJsonToValue), toListValue);
const convertJsonToValue = (json) => (0, import_fp_utils.firstRight)(json, { ...defaultValue, nullValue: import_v1.NullValue.NULL_VALUE }, [
  [(json2) => typeof json2 === "number", (json2) => ({ ...defaultValue, numberValue: json2 })],
  [(json2) => typeof json2 === "string", (json2) => ({ ...defaultValue, stringValue: json2 })],
  [(json2) => typeof json2 === "boolean", (json2) => ({ ...defaultValue, boolValue: json2 })],
  [
    (json2) => Array.isArray(json2),
    (json2) => ({ ...defaultValue, listValue: convertJsonToList(json2) })
  ],
  [
    (json2) => import_lodash.default.isObject(json2),
    (json2) => ({ ...defaultValue, structValue: convertJsonToStruct(json2) })
  ]
]);
const convertJsonToStruct = (0, import_function.flow)(
  Object.entries,
  A.map(T.bimap(convertJsonToValue, import_function.identity)),
  A.map(toRecord),
  (0, import_Monoid.concatAll)(valueM),
  toStruct
);
//# sourceMappingURL=convert-json-to-struct.js.map
