// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Decco from "decco/src/Decco.bs.js";
import * as Js_dict from "rescript/lib/es6/js_dict.js";
import * as Js_json from "rescript/lib/es6/js_json.js";
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
import * as Caml_array from "rescript/lib/es6/caml_array.js";
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as Types__Common from "./Types__Common.bs.js";

function field_encode(v) {
  return Js_dict.fromArray([
              [
                "sourceKey",
                Decco.stringToJson(v.sourceKey)
              ],
              [
                "targetType",
                Decco.stringToJson(v.targetType)
              ]
            ]);
}

function field_decode(v) {
  var dict = Js_json.classify(v);
  if (typeof dict === "number") {
    return Decco.error(undefined, "Not an object", v);
  }
  if (dict.TAG !== /* JSONObject */2) {
    return Decco.error(undefined, "Not an object", v);
  }
  var dict$1 = dict._0;
  var sourceKey = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "sourceKey"), null));
  if (sourceKey.TAG === /* Ok */0) {
    var targetType = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "targetType"), null));
    if (targetType.TAG === /* Ok */0) {
      return {
              TAG: /* Ok */0,
              _0: {
                sourceKey: sourceKey._0,
                targetType: targetType._0
              }
            };
    }
    var e = targetType._0;
    return {
            TAG: /* Error */1,
            _0: {
              path: ".targetType" + e.path,
              message: e.message,
              value: e.value
            }
          };
  }
  var e$1 = sourceKey._0;
  return {
          TAG: /* Error */1,
          _0: {
            path: ".sourceKey" + e$1.path,
            message: e$1.message,
            value: e$1.value
          }
        };
}

function locate_encode(v) {
  return Js_dict.fromArray([
              [
                "latitudeKey",
                Decco.optionToJson(Decco.stringToJson, v.latitudeKey)
              ],
              [
                "longitudeKey",
                Decco.optionToJson(Decco.stringToJson, v.longitudeKey)
              ],
              [
                "addressKey",
                Decco.optionToJson(Decco.stringToJson, v.addressKey)
              ],
              [
                "cityKey",
                Decco.optionToJson(Decco.stringToJson, v.cityKey)
              ],
              [
                "stateKey",
                Decco.optionToJson(Decco.stringToJson, v.stateKey)
              ],
              [
                "zipKey",
                Decco.optionToJson(Decco.stringToJson, v.zipKey)
              ]
            ]);
}

function locate_decode(v) {
  var dict = Js_json.classify(v);
  if (typeof dict === "number") {
    return Decco.error(undefined, "Not an object", v);
  }
  if (dict.TAG !== /* JSONObject */2) {
    return Decco.error(undefined, "Not an object", v);
  }
  var dict$1 = dict._0;
  var latitudeKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "latitudeKey"), null));
  if (latitudeKey.TAG === /* Ok */0) {
    var longitudeKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "longitudeKey"), null));
    if (longitudeKey.TAG === /* Ok */0) {
      var addressKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "addressKey"), null));
      if (addressKey.TAG === /* Ok */0) {
        var cityKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "cityKey"), null));
        if (cityKey.TAG === /* Ok */0) {
          var stateKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "stateKey"), null));
          if (stateKey.TAG === /* Ok */0) {
            var zipKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "zipKey"), null));
            if (zipKey.TAG === /* Ok */0) {
              return {
                      TAG: /* Ok */0,
                      _0: {
                        latitudeKey: latitudeKey._0,
                        longitudeKey: longitudeKey._0,
                        addressKey: addressKey._0,
                        cityKey: cityKey._0,
                        stateKey: stateKey._0,
                        zipKey: zipKey._0
                      }
                    };
            }
            var e = zipKey._0;
            return {
                    TAG: /* Error */1,
                    _0: {
                      path: ".zipKey" + e.path,
                      message: e.message,
                      value: e.value
                    }
                  };
          }
          var e$1 = stateKey._0;
          return {
                  TAG: /* Error */1,
                  _0: {
                    path: ".stateKey" + e$1.path,
                    message: e$1.message,
                    value: e$1.value
                  }
                };
        }
        var e$2 = cityKey._0;
        return {
                TAG: /* Error */1,
                _0: {
                  path: ".cityKey" + e$2.path,
                  message: e$2.message,
                  value: e$2.value
                }
              };
      }
      var e$3 = addressKey._0;
      return {
              TAG: /* Error */1,
              _0: {
                path: ".addressKey" + e$3.path,
                message: e$3.message,
                value: e$3.value
              }
            };
    }
    var e$4 = longitudeKey._0;
    return {
            TAG: /* Error */1,
            _0: {
              path: ".longitudeKey" + e$4.path,
              message: e$4.message,
              value: e$4.value
            }
          };
  }
  var e$5 = latitudeKey._0;
  return {
          TAG: /* Error */1,
          _0: {
            path: ".latitudeKey" + e$5.path,
            message: e$5.message,
            value: e$5.value
          }
        };
}

function contact_encode(v) {
  return Js_dict.fromArray([
              [
                "contactNameKey",
                Decco.optionToJson(Decco.stringToJson, v.contactNameKey)
              ],
              [
                "contactAddressKey",
                Decco.optionToJson(Decco.stringToJson, v.contactAddressKey)
              ],
              [
                "contactEmailKeys",
                Decco.arrayToJson((function (param) {
                        return Decco.optionToJson(Decco.stringToJson, param);
                      }), v.contactEmailKeys)
              ],
              [
                "contactPhoneKeys",
                Decco.arrayToJson((function (param) {
                        return Decco.optionToJson(Decco.stringToJson, param);
                      }), v.contactPhoneKeys)
              ]
            ]);
}

function contact_decode(v) {
  var dict = Js_json.classify(v);
  if (typeof dict === "number") {
    return Decco.error(undefined, "Not an object", v);
  }
  if (dict.TAG !== /* JSONObject */2) {
    return Decco.error(undefined, "Not an object", v);
  }
  var dict$1 = dict._0;
  var contactNameKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "contactNameKey"), null));
  if (contactNameKey.TAG === /* Ok */0) {
    var contactAddressKey = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "contactAddressKey"), null));
    if (contactAddressKey.TAG === /* Ok */0) {
      var contactEmailKeys = Decco.arrayFromJson((function (param) {
              return Decco.optionFromJson(Decco.stringFromJson, param);
            }), Belt_Option.getWithDefault(Js_dict.get(dict$1, "contactEmailKeys"), null));
      if (contactEmailKeys.TAG === /* Ok */0) {
        var contactPhoneKeys = Decco.arrayFromJson((function (param) {
                return Decco.optionFromJson(Decco.stringFromJson, param);
              }), Belt_Option.getWithDefault(Js_dict.get(dict$1, "contactPhoneKeys"), null));
        if (contactPhoneKeys.TAG === /* Ok */0) {
          return {
                  TAG: /* Ok */0,
                  _0: {
                    contactNameKey: contactNameKey._0,
                    contactAddressKey: contactAddressKey._0,
                    contactEmailKeys: contactEmailKeys._0,
                    contactPhoneKeys: contactPhoneKeys._0
                  }
                };
        }
        var e = contactPhoneKeys._0;
        return {
                TAG: /* Error */1,
                _0: {
                  path: ".contactPhoneKeys" + e.path,
                  message: e.message,
                  value: e.value
                }
              };
      }
      var e$1 = contactEmailKeys._0;
      return {
              TAG: /* Error */1,
              _0: {
                path: ".contactEmailKeys" + e$1.path,
                message: e$1.message,
                value: e$1.value
              }
            };
    }
    var e$2 = contactAddressKey._0;
    return {
            TAG: /* Error */1,
            _0: {
              path: ".contactAddressKey" + e$2.path,
              message: e$2.message,
              value: e$2.value
            }
          };
  }
  var e$3 = contactNameKey._0;
  return {
          TAG: /* Error */1,
          _0: {
            path: ".contactNameKey" + e$3.path,
            message: e$3.message,
            value: e$3.value
          }
        };
}

function schema_encode(v) {
  return Js_dict.fromArray([
              [
                "targetTeamId",
                Decco.stringToJson(v.targetTeamId)
              ],
              [
                "maptableName",
                Decco.stringToJson(v.maptableName)
              ],
              [
                "existingMaptableId",
                Decco.optionToJson(Decco.stringToJson, v.existingMaptableId)
              ],
              [
                "source",
                Decco.optionToJson(Decco.stringToJson, v.source)
              ],
              [
                "locate",
                Decco.optionToJson(locate_encode, v.locate)
              ],
              [
                "contacts",
                Decco.optionToJson((function (param) {
                        return Decco.arrayToJson(contact_encode, param);
                      }), v.contacts)
              ],
              [
                "fields",
                Decco.arrayToJson(field_encode, v.fields)
              ],
              [
                "isTemplate",
                Decco.boolToJson(v.isTemplate)
              ]
            ]);
}

function schema_decode(v) {
  var dict = Js_json.classify(v);
  if (typeof dict === "number") {
    return Decco.error(undefined, "Not an object", v);
  }
  if (dict.TAG !== /* JSONObject */2) {
    return Decco.error(undefined, "Not an object", v);
  }
  var dict$1 = dict._0;
  var targetTeamId = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "targetTeamId"), null));
  if (targetTeamId.TAG === /* Ok */0) {
    var maptableName = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "maptableName"), null));
    if (maptableName.TAG === /* Ok */0) {
      var existingMaptableId = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "existingMaptableId"), null));
      if (existingMaptableId.TAG === /* Ok */0) {
        var source = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "source"), null));
        if (source.TAG === /* Ok */0) {
          var locate = Decco.optionFromJson(locate_decode, Belt_Option.getWithDefault(Js_dict.get(dict$1, "locate"), null));
          if (locate.TAG === /* Ok */0) {
            var contacts = Decco.optionFromJson((function (param) {
                    return Decco.arrayFromJson(contact_decode, param);
                  }), Belt_Option.getWithDefault(Js_dict.get(dict$1, "contacts"), null));
            if (contacts.TAG === /* Ok */0) {
              var fields = Decco.arrayFromJson(field_decode, Belt_Option.getWithDefault(Js_dict.get(dict$1, "fields"), null));
              if (fields.TAG === /* Ok */0) {
                var isTemplate = Belt_Option.getWithDefault(Belt_Option.map(Js_dict.get(dict$1, "isTemplate"), Decco.boolFromJson), {
                      TAG: /* Ok */0,
                      _0: false
                    });
                if (isTemplate.TAG === /* Ok */0) {
                  return {
                          TAG: /* Ok */0,
                          _0: {
                            targetTeamId: targetTeamId._0,
                            maptableName: maptableName._0,
                            existingMaptableId: existingMaptableId._0,
                            source: source._0,
                            locate: locate._0,
                            contacts: contacts._0,
                            fields: fields._0,
                            isTemplate: isTemplate._0
                          }
                        };
                }
                var e = isTemplate._0;
                return {
                        TAG: /* Error */1,
                        _0: {
                          path: ".isTemplate" + e.path,
                          message: e.message,
                          value: e.value
                        }
                      };
              }
              var e$1 = fields._0;
              return {
                      TAG: /* Error */1,
                      _0: {
                        path: ".fields" + e$1.path,
                        message: e$1.message,
                        value: e$1.value
                      }
                    };
            }
            var e$2 = contacts._0;
            return {
                    TAG: /* Error */1,
                    _0: {
                      path: ".contacts" + e$2.path,
                      message: e$2.message,
                      value: e$2.value
                    }
                  };
          }
          var e$3 = locate._0;
          return {
                  TAG: /* Error */1,
                  _0: {
                    path: ".locate" + e$3.path,
                    message: e$3.message,
                    value: e$3.value
                  }
                };
        }
        var e$4 = source._0;
        return {
                TAG: /* Error */1,
                _0: {
                  path: ".source" + e$4.path,
                  message: e$4.message,
                  value: e$4.value
                }
              };
      }
      var e$5 = existingMaptableId._0;
      return {
              TAG: /* Error */1,
              _0: {
                path: ".existingMaptableId" + e$5.path,
                message: e$5.message,
                value: e$5.value
              }
            };
    }
    var e$6 = maptableName._0;
    return {
            TAG: /* Error */1,
            _0: {
              path: ".maptableName" + e$6.path,
              message: e$6.message,
              value: e$6.value
            }
          };
  }
  var e$7 = targetTeamId._0;
  return {
          TAG: /* Error */1,
          _0: {
            path: ".targetTeamId" + e$7.path,
            message: e$7.message,
            value: e$7.value
          }
        };
}

var defaultImport_sourceColumns = [];

var defaultImport_targetColumns = [];

var defaultImport_schema = {
  targetTeamId: "",
  maptableName: "",
  existingMaptableId: undefined,
  source: undefined,
  locate: undefined,
  contacts: undefined,
  fields: [],
  isTemplate: false
};

var defaultImport = {
  file: undefined,
  sourceColumns: defaultImport_sourceColumns,
  targetColumns: defaultImport_targetColumns,
  schema: defaultImport_schema
};

function t_encode(v) {
  return Js_dict.fromArray([
              [
                "id",
                Types__Common.ImportId.t_encode(v.id)
              ],
              [
                "maptableId",
                Decco.optionToJson(Decco.stringToJson, v.maptableId)
              ],
              [
                "schema",
                schema_encode(v.schema)
              ],
              [
                "csvColumns",
                Decco.stringToJson(v.csvColumns)
              ],
              [
                "status",
                Decco.stringToJson(v.status)
              ],
              [
                "sourceCount",
                Decco.intToJson(v.sourceCount)
              ],
              [
                "resultCount",
                Decco.intToJson(v.resultCount)
              ],
              [
                "endDate",
                Decco.optionToJson(Decco.stringToJson, v.endDate)
              ],
              [
                "startDate",
                Decco.stringToJson(v.startDate)
              ],
              [
                "errorAddresses",
                Decco.arrayToJson(Decco.stringToJson, v.errorAddresses)
              ]
            ]);
}

function t_decode(v) {
  var dict = Js_json.classify(v);
  if (typeof dict === "number") {
    return Decco.error(undefined, "Not an object", v);
  }
  if (dict.TAG !== /* JSONObject */2) {
    return Decco.error(undefined, "Not an object", v);
  }
  var dict$1 = dict._0;
  var id = Types__Common.ImportId.t_decode(Belt_Option.getWithDefault(Js_dict.get(dict$1, "id"), null));
  if (id.TAG === /* Ok */0) {
    var maptableId = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "maptableId"), null));
    if (maptableId.TAG === /* Ok */0) {
      var schema = schema_decode(Belt_Option.getWithDefault(Js_dict.get(dict$1, "schema"), null));
      if (schema.TAG === /* Ok */0) {
        var csvColumns = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "csvColumns"), null));
        if (csvColumns.TAG === /* Ok */0) {
          var status = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "status"), null));
          if (status.TAG === /* Ok */0) {
            var sourceCount = Decco.intFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "sourceCount"), null));
            if (sourceCount.TAG === /* Ok */0) {
              var resultCount = Decco.intFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "resultCount"), null));
              if (resultCount.TAG === /* Ok */0) {
                var endDate = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "endDate"), null));
                if (endDate.TAG === /* Ok */0) {
                  var startDate = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "startDate"), null));
                  if (startDate.TAG === /* Ok */0) {
                    var errorAddresses = Decco.arrayFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "errorAddresses"), null));
                    if (errorAddresses.TAG === /* Ok */0) {
                      return {
                              TAG: /* Ok */0,
                              _0: {
                                id: id._0,
                                maptableId: maptableId._0,
                                schema: schema._0,
                                csvColumns: csvColumns._0,
                                status: status._0,
                                sourceCount: sourceCount._0,
                                resultCount: resultCount._0,
                                endDate: endDate._0,
                                startDate: startDate._0,
                                errorAddresses: errorAddresses._0
                              }
                            };
                    }
                    var e = errorAddresses._0;
                    return {
                            TAG: /* Error */1,
                            _0: {
                              path: ".errorAddresses" + e.path,
                              message: e.message,
                              value: e.value
                            }
                          };
                  }
                  var e$1 = startDate._0;
                  return {
                          TAG: /* Error */1,
                          _0: {
                            path: ".startDate" + e$1.path,
                            message: e$1.message,
                            value: e$1.value
                          }
                        };
                }
                var e$2 = endDate._0;
                return {
                        TAG: /* Error */1,
                        _0: {
                          path: ".endDate" + e$2.path,
                          message: e$2.message,
                          value: e$2.value
                        }
                      };
              }
              var e$3 = resultCount._0;
              return {
                      TAG: /* Error */1,
                      _0: {
                        path: ".resultCount" + e$3.path,
                        message: e$3.message,
                        value: e$3.value
                      }
                    };
            }
            var e$4 = sourceCount._0;
            return {
                    TAG: /* Error */1,
                    _0: {
                      path: ".sourceCount" + e$4.path,
                      message: e$4.message,
                      value: e$4.value
                    }
                  };
          }
          var e$5 = status._0;
          return {
                  TAG: /* Error */1,
                  _0: {
                    path: ".status" + e$5.path,
                    message: e$5.message,
                    value: e$5.value
                  }
                };
        }
        var e$6 = csvColumns._0;
        return {
                TAG: /* Error */1,
                _0: {
                  path: ".csvColumns" + e$6.path,
                  message: e$6.message,
                  value: e$6.value
                }
              };
      }
      var e$7 = schema._0;
      return {
              TAG: /* Error */1,
              _0: {
                path: ".schema" + e$7.path,
                message: e$7.message,
                value: e$7.value
              }
            };
    }
    var e$8 = maptableId._0;
    return {
            TAG: /* Error */1,
            _0: {
              path: ".maptableId" + e$8.path,
              message: e$8.message,
              value: e$8.value
            }
          };
  }
  var e$9 = id._0;
  return {
          TAG: /* Error */1,
          _0: {
            path: ".id" + e$9.path,
            message: e$9.message,
            value: e$9.value
          }
        };
}

function firebase_encode(v) {
  return Js_dict.fromArray([
              [
                "maptableId",
                Decco.optionToJson(Decco.stringToJson, v.maptableId)
              ],
              [
                "schema",
                schema_encode(v.schema)
              ],
              [
                "csvColumns",
                Decco.stringToJson(v.csvColumns)
              ],
              [
                "status",
                Decco.stringToJson(v.status)
              ],
              [
                "sourceCount",
                Decco.intToJson(v.sourceCount)
              ],
              [
                "resultCount",
                Decco.intToJson(v.resultCount)
              ],
              [
                "endDate",
                Decco.optionToJson(Decco.stringToJson, v.endDate)
              ],
              [
                "startDate",
                Decco.stringToJson(v.startDate)
              ],
              [
                "errorAddresses",
                Decco.arrayToJson(Decco.stringToJson, v.errorAddresses)
              ]
            ]);
}

function firebase_decode(v) {
  var dict = Js_json.classify(v);
  if (typeof dict === "number") {
    return Decco.error(undefined, "Not an object", v);
  }
  if (dict.TAG !== /* JSONObject */2) {
    return Decco.error(undefined, "Not an object", v);
  }
  var dict$1 = dict._0;
  var maptableId = Belt_Option.getWithDefault(Belt_Option.map(Js_dict.get(dict$1, "maptableId"), (function (param) {
              return Decco.optionFromJson(Decco.stringFromJson, param);
            })), {
        TAG: /* Ok */0,
        _0: undefined
      });
  if (maptableId.TAG === /* Ok */0) {
    var schema = schema_decode(Belt_Option.getWithDefault(Js_dict.get(dict$1, "schema"), null));
    if (schema.TAG === /* Ok */0) {
      var csvColumns = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "csvColumns"), null));
      if (csvColumns.TAG === /* Ok */0) {
        var status = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "status"), null));
        if (status.TAG === /* Ok */0) {
          var sourceCount = Decco.intFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "sourceCount"), null));
          if (sourceCount.TAG === /* Ok */0) {
            var resultCount = Decco.intFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "resultCount"), null));
            if (resultCount.TAG === /* Ok */0) {
              var endDate = Decco.optionFromJson(Decco.stringFromJson, Belt_Option.getWithDefault(Js_dict.get(dict$1, "endDate"), null));
              if (endDate.TAG === /* Ok */0) {
                var startDate = Decco.stringFromJson(Belt_Option.getWithDefault(Js_dict.get(dict$1, "startDate"), null));
                if (startDate.TAG === /* Ok */0) {
                  var errorAddresses = Belt_Option.getWithDefault(Belt_Option.map(Js_dict.get(dict$1, "errorAddresses"), (function (param) {
                              return Decco.arrayFromJson(Decco.stringFromJson, param);
                            })), {
                        TAG: /* Ok */0,
                        _0: []
                      });
                  if (errorAddresses.TAG === /* Ok */0) {
                    return {
                            TAG: /* Ok */0,
                            _0: {
                              maptableId: maptableId._0,
                              schema: schema._0,
                              csvColumns: csvColumns._0,
                              status: status._0,
                              sourceCount: sourceCount._0,
                              resultCount: resultCount._0,
                              endDate: endDate._0,
                              startDate: startDate._0,
                              errorAddresses: errorAddresses._0
                            }
                          };
                  }
                  var e = errorAddresses._0;
                  return {
                          TAG: /* Error */1,
                          _0: {
                            path: ".errorAddresses" + e.path,
                            message: e.message,
                            value: e.value
                          }
                        };
                }
                var e$1 = startDate._0;
                return {
                        TAG: /* Error */1,
                        _0: {
                          path: ".startDate" + e$1.path,
                          message: e$1.message,
                          value: e$1.value
                        }
                      };
              }
              var e$2 = endDate._0;
              return {
                      TAG: /* Error */1,
                      _0: {
                        path: ".endDate" + e$2.path,
                        message: e$2.message,
                        value: e$2.value
                      }
                    };
            }
            var e$3 = resultCount._0;
            return {
                    TAG: /* Error */1,
                    _0: {
                      path: ".resultCount" + e$3.path,
                      message: e$3.message,
                      value: e$3.value
                    }
                  };
          }
          var e$4 = sourceCount._0;
          return {
                  TAG: /* Error */1,
                  _0: {
                    path: ".sourceCount" + e$4.path,
                    message: e$4.message,
                    value: e$4.value
                  }
                };
        }
        var e$5 = status._0;
        return {
                TAG: /* Error */1,
                _0: {
                  path: ".status" + e$5.path,
                  message: e$5.message,
                  value: e$5.value
                }
              };
      }
      var e$6 = csvColumns._0;
      return {
              TAG: /* Error */1,
              _0: {
                path: ".csvColumns" + e$6.path,
                message: e$6.message,
                value: e$6.value
              }
            };
    }
    var e$7 = schema._0;
    return {
            TAG: /* Error */1,
            _0: {
              path: ".schema" + e$7.path,
              message: e$7.message,
              value: e$7.value
            }
          };
  }
  var e$8 = maptableId._0;
  return {
          TAG: /* Error */1,
          _0: {
            path: ".maptableId" + e$8.path,
            message: e$8.message,
            value: e$8.value
          }
        };
}

function parseSchema(dataList) {
  var index = Belt_Array.getIndexBy(dataList, (function (item) {
          return item.includes("name=\"schema\"");
        }));
  if (index === undefined) {
    return ;
  }
  var schema = schema_decode(JSON.parse(Caml_array.get(dataList, index + 2 | 0)));
  if (schema.TAG === /* Ok */0) {
    return schema._0;
  }
  
}

function makeLabels(id, maptableId, schema, csvColumns, status, sourceCount, resultCount, endDateOpt, errorAddresses, startDate) {
  var endDate = endDateOpt !== undefined ? Caml_option.valFromOption(endDateOpt) : undefined;
  return {
          id: id,
          maptableId: maptableId,
          schema: schema,
          csvColumns: csvColumns,
          status: status,
          sourceCount: sourceCount,
          resultCount: resultCount,
          endDate: endDate,
          startDate: startDate,
          errorAddresses: errorAddresses
        };
}

function completeImport(importType, result, errors, newSpaceId) {
  return makeLabels(importType.id, newSpaceId, importType.schema, importType.csvColumns, "Complete", importType.sourceCount, result, Caml_option.some(new Date().toString()), Belt_Array.map(errors, (function (item) {
                    return Belt_Option.getWithDefault(Js_dict.get(item.data, "coordinate"), "Unknown");
                  })), importType.startDate);
}

var Id;

export {
  Id ,
  field_encode ,
  field_decode ,
  locate_encode ,
  locate_decode ,
  contact_encode ,
  contact_decode ,
  schema_encode ,
  schema_decode ,
  defaultImport ,
  t_encode ,
  t_decode ,
  firebase_encode ,
  firebase_decode ,
  parseSchema ,
  makeLabels ,
  completeImport ,
}
/* Types__Common Not a pure module */
