"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getCustomFieldResolver = getCustomFieldResolver;
exports.getFieldDeserializer = getFieldDeserializer;
exports.getFieldSerializer = getFieldSerializer;
exports.getUserFieldContextProvider = getUserFieldContextProvider;
function getExtensionModuleField(manifest, fieldType, handlerLink) {
  if (!handlerLink.type) {
    throw new Error("Missing type!");
  }
  if (!manifest.modules.fields) {
    throw new Error("No definition of fields for extension type \"".concat(manifest.type, "\" and key \"").concat(manifest.key, "\""));
  }
  if (!manifest.modules.fields[fieldType]) {
    throw new Error("No definition for field type \"".concat(fieldType, "\" on manifest for extension with type \"").concat(manifest.type, "\" and key \"").concat(manifest.key, "\""));
  }
  var type = handlerLink.type;
  // Ignored via go/ees005
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  var handler = manifest.modules.fields[fieldType][type];
  if (!handler) {
    throw new Error("No handler of type \"".concat(type, "\" for extension type \"").concat(manifest.type, "\" and key \"").concat(manifest.key, "\""));
  }
  return handler;
}

/** attempt to get the custom resolver for this field, or throw */
function getCustomFieldResolver(manifest, handlerLink) {
  var handler = getExtensionModuleField(manifest, 'custom', handlerLink);
  return handler.resolver;
}

/** attempt to get the serializer for this field, or throw */
function getFieldSerializer(manifest, handlerLink) {
  var handler = getExtensionModuleField(manifest, 'fieldset', handlerLink);
  return handler.serializer;
}

/** attempt to get the deserializer for this field, or throw */
function getFieldDeserializer(manifest, handlerLink) {
  var handler = getExtensionModuleField(manifest, 'fieldset', handlerLink);
  return handler.deserializer;
}

/** attempt to get the user field context provider for this field, or throw */
function getUserFieldContextProvider(manifest, handlerLink) {
  var handler = getExtensionModuleField(manifest, 'user', handlerLink);
  return handler.provider;
}