import DefaultCallbackHandler130 from "./assets/v1.1.1/default_callback_handler.json";
import CompatibilityFallbackHandler131 from "./assets/v1.3.1/compatibility_fallback_handler.json";
import CompatibilityFallbackHandler from "./assets/v1.3.0/compatibility_fallback_handler.json";
import { DeploymentFilter, SingletonDeployment } from "./types";
import { applyFilterDefaults, findDeployment } from "./utils";

// This is a sorted array (by preference)
const defaultCallbackHandlerDeployments: SingletonDeployment[] = [
  DefaultCallbackHandler130,
];

export const getDefaultCallbackHandlerDeployment = (
  filter?: DeploymentFilter
): SingletonDeployment | undefined => {
  return findDeployment(
    applyFilterDefaults(filter),
    defaultCallbackHandlerDeployments
  );
};

// This is a sorted array (by preference)
const compatFallbackHandlerDeployments: SingletonDeployment[] = [
  CompatibilityFallbackHandler131,
  CompatibilityFallbackHandler,
];

export const getCompatibilityFallbackHandlerDeployment = (
  filter?: DeploymentFilter
): SingletonDeployment | undefined => {
  return findDeployment(
    applyFilterDefaults(filter),
    compatFallbackHandlerDeployments
  );
};

// This is a sorted array (by preference)
const fallbackHandlerDeployments: SingletonDeployment[] = [
  CompatibilityFallbackHandler131,
  CompatibilityFallbackHandler,
  DefaultCallbackHandler130,
];

export const getFallbackHandlerDeployment = (
  filter?: DeploymentFilter
): SingletonDeployment | undefined => {
  return findDeployment(
    applyFilterDefaults(filter),
    fallbackHandlerDeployments
  );
};
