"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getMergeFunction = getMergeFunction;
exports.getPolishFunction = getPolishFunction;

var _coatManifestFile = require("../types/coat-manifest-file");

var _json = require("./json");

var _text = require("./text");

var _yaml = require("./yaml");

const fileTypeRegistry = {
  [_coatManifestFile.CoatManifestFileType.Json]: _json.jsonFileFunctions,
  [_coatManifestFile.CoatManifestFileType.Text]: _text.textFileFunctions,
  [_coatManifestFile.CoatManifestFileType.Yaml]: _yaml.yamlFileFunctions
};
/**
 * Retrieves the merge function for the specified file type.
 * This function is currently necessary to correctly cast the
 * type of the merge function to the correct file type.
 */

function getMergeFunction(file) {
  const fileFunctions = fileTypeRegistry[file.type];

  if (!fileFunctions) {
    throw new Error(`Cannot merge unknown file type: ${file.type}`);
  }

  return fileFunctions.merge;
}
/**
 * Retrieves the polish function for the specified file type.
 * This function is currently necessary to correctly cast the
 * type of the polish function to the correct file type.
 */


function getPolishFunction(file) {
  const fileFunctions = fileTypeRegistry[file.type];

  if (!fileFunctions) {
    throw new Error(`Cannot polish unknown file type: ${file.type}`);
  }

  return fileFunctions.polish;
}