import { models } from '../../database/schemas/models.js';

/**
 * Get all models from the PREFIX_MODEL_MAP
 * @returns {Array} Array of model entries with model, idField, and type properties
 */
export const getAllModels = () => {
  return Object.values(models);
};

/**
 * Get a model by its type name
 * @param {string} name - The type name of the model (e.g., 'printer', 'filament', 'job')
 * @returns {Object|null} The model entry or null if not found
 */
export const getModelByName = (name) => {
  const entry = Object.values(models).find((entry) => entry.type === name);
  return entry || null;
};

/**
 * Get a model by its prefix
 * @param {string} prefix - The prefix of the model (e.g., 'PRN', 'FIL', 'JOB')
 * @returns {Object|null} The model entry or null if not found
 */
export const getModelByPrefix = (prefix) => {
  return models[prefix] || null;
};

// Export the PREFIX_MODEL_MAP for backward compatibility
export { models };
