// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Curry from "rescript/lib/es6/curry.js";
import * as Js_dict from "rescript/lib/es6/js_dict.js";
import * as Belt_Map from "rescript/lib/es6/belt_Map.js";
import * as Js_string from "rescript/lib/es6/js_string.js";
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
import * as DeccoExtra from "./DeccoExtra.bs.js";
import * as Belt_MapString from "rescript/lib/es6/belt_MapString.js";
import * as S$RescriptStruct from "rescript-struct/src/S.bs.js";
import ParseISO from "date-fns/parseISO";
import FormatISO from "date-fns/formatISO";

function objectAsEntries(keyParserOpt, keySerializerOpt, valueStruct) {
  var keyParser = keyParserOpt !== undefined ? keyParserOpt : (function (prim) {
        return prim;
      });
  var keySerializer = keySerializerOpt !== undefined ? keySerializerOpt : (function (prim) {
        return prim;
      });
  return S$RescriptStruct.transform(S$RescriptStruct.dict(valueStruct), (function (x) {
                return Belt_Array.map(Js_dict.entries(x), (function (param) {
                              return [
                                      Curry._1(keyParser, param[0]),
                                      param[1]
                                    ];
                            }));
              }), undefined, (function (x) {
                return Js_dict.fromArray(Belt_Array.map(x, (function (param) {
                                  return [
                                          Curry._1(keySerializer, param[0]),
                                          param[1]
                                        ];
                                })));
              }), undefined);
}

function objectAsMap(id, keyParserOpt, keySerializerOpt, valueStruct) {
  var keyParser = keyParserOpt !== undefined ? keyParserOpt : (function (prim) {
        return prim;
      });
  var keySerializer = keySerializerOpt !== undefined ? keySerializerOpt : (function (prim) {
        return prim;
      });
  return S$RescriptStruct.transform(S$RescriptStruct.dict(valueStruct), (function (x) {
                return Belt_Map.fromArray(Belt_Array.map(Js_dict.entries(x), (function (param) {
                                  return [
                                          Curry._1(keyParser, param[0]),
                                          param[1]
                                        ];
                                })), id);
              }), undefined, (function (x) {
                return Js_dict.fromArray(Belt_Array.map(Belt_Map.toArray(x), (function (param) {
                                  return [
                                          Curry._1(keySerializer, param[0]),
                                          param[1]
                                        ];
                                })));
              }), undefined);
}

function objectAsMapString(innerStruct) {
  return S$RescriptStruct.transform(S$RescriptStruct.dict(innerStruct), (function (x) {
                return Belt_MapString.fromArray(Js_dict.entries(x));
              }), undefined, (function (x) {
                return Js_dict.fromArray(Belt_MapString.toArray(x));
              }), undefined);
}

function $$default(struct, f) {
  return S$RescriptStruct.$$default(S$RescriptStruct.option(struct), f);
}

function decco(encoder, decoder) {
  return S$RescriptStruct.custom("decco", (function (x) {
                var x$1 = Curry._1(decoder, x);
                if (x$1.TAG === /* Ok */0) {
                  return x$1._0;
                } else {
                  return S$RescriptStruct.fail(undefined, DeccoExtra.errorToString(x$1._0));
                }
              }), undefined, Curry.__1(encoder), undefined);
}

function $$const(x) {
  return S$RescriptStruct.custom("const", (function (param) {
                return x;
              }), undefined, (function (param) {
                return x;
              }), undefined);
}

var dateNoTime = S$RescriptStruct.transform(S$RescriptStruct.string(undefined), (function (x) {
        return ParseISO(Js_string.substring(0, 10, x));
      }), undefined, (function (x) {
        return Js_string.substring(0, 10, FormatISO(x));
      }), undefined);

function safeNull(struct) {
  return S$RescriptStruct.$$default(S$RescriptStruct.option(S$RescriptStruct.$$null(struct)), (function (param) {
                
              }));
}

export {
  objectAsEntries ,
  objectAsMap ,
  objectAsMapString ,
  $$default ,
  $$default as default,
  decco ,
  $$const ,
  dateNoTime ,
  safeNull ,
}
/* dateNoTime Not a pure module */
