import { PluginConstructor, PluginData } from "../shared/src/plugin.js";
import { ResourceEntry, ResourceRequirement, ValidationResult } from "./types.js";

//#region src/registry/resource-registry.d.ts

/**
 * Central registry for tracking plugin resource requirements.
 * Deduplication uses type + resourceKey (machine-stable); alias is for display only.
 */
declare class ResourceRegistry {
  private resources;
  /**
   * Registers a resource requirement for a plugin.
   * If a resource with the same type+resourceKey already exists, merges them:
   * - Combines plugin names (comma-separated)
   * - Uses the most permissive permission (per-type hierarchy)
   * - Marks as required if any plugin requires it
   * - Combines descriptions if they differ
   * - Merges fields; warns when same field name uses different env vars
   *
   * @param plugin - Name of the plugin registering the resource
   * @param resource - Resource requirement specification
   */
  register(plugin: string, resource: ResourceRequirement): void;
  /**
   * Collects and registers resource requirements from an array of plugins.
   * For each plugin, loads its manifest (required) and runtime resource requirements.
   *
   * @param rawPlugins - Array of plugin data entries from createApp configuration
   * @throws {ConfigurationError} If any plugin is missing a manifest or manifest is invalid
   */
  collectResources(rawPlugins: PluginData<PluginConstructor, unknown, string>[]): void;
  /**
   * Merges a new resource requirement with an existing entry.
   * Applies intelligent merging logic for conflicting properties.
   */
  private mergeResources;
  /**
   * Retrieves all registered resources.
   * Returns a copy of the array to prevent external mutations.
   *
   * @returns Array of all registered resource entries
   */
  getAll(): ResourceEntry[];
  /**
   * Gets a specific resource by type and resourceKey (dedup key).
   *
   * @param type - Resource type
   * @param resourceKey - Stable machine key (not alias; alias is for display only)
   * @returns The resource entry if found, undefined otherwise
   */
  get(type: string, resourceKey: string): ResourceEntry | undefined;
  /**
   * Clears all registered resources.
   * Useful for testing or when rebuilding the registry.
   */
  clear(): void;
  /**
   * Returns the number of registered resources.
   */
  size(): number;
  /**
   * Gets all resources required by a specific plugin.
   *
   * @param pluginName - Name of the plugin
   * @returns Array of resources where the plugin is listed as a requester
   */
  getByPlugin(pluginName: string): ResourceEntry[];
  /**
   * Gets all required resources (where required=true).
   *
   * @returns Array of required resource entries
   */
  getRequired(): ResourceEntry[];
  /**
   * Gets all optional resources (where required=false).
   *
   * @returns Array of optional resource entries
   */
  getOptional(): ResourceEntry[];
  /**
   * Validates all registered resources against the environment.
   *
   * Checks each resource's field environment variables to determine if it's resolved.
   * Updates the `resolved` and `values` fields on each resource entry.
   *
   * Only required resources affect the `valid` status - optional resources
   * are checked but don't cause validation failure.
   *
   * @returns ValidationResult with validity status, missing resources, and all resources
   *
   * @example
   * ```typescript
   * const registry = ResourceRegistry.getInstance();
   * const result = registry.validate();
   *
   * if (!result.valid) {
   *   console.error("Missing resources:", result.missing.map(r => Object.values(r.fields).map(f => f.env)));
   * }
   * ```
   */
  validate(): ValidationResult;
  /**
   * Validates all registered resources and enforces the result.
   *
   * - In production: throws a {@link ConfigurationError} if any required resources are missing.
   * - In development (`NODE_ENV=development`): logs a warning but continues, unless
   *   `APPKIT_STRICT_VALIDATION=true` is set, in which case throws like production.
   * - When all resources are valid: logs a debug message with the count.
   *
   * @returns ValidationResult with validity status, missing resources, and all resources
   * @throws {ConfigurationError} In production when required resources are missing, or in dev when APPKIT_STRICT_VALIDATION=true
   */
  enforceValidation(): ValidationResult;
  /**
   * Formats missing resources into a human-readable error message.
   *
   * @param missing - Array of missing resource entries
   * @returns Formatted error message string
   */
  static formatMissingResources(missing: ResourceEntry[]): string;
  /**
   * Formats a highly visible warning banner for dev-mode missing resources.
   * Uses box drawing to ensure the message is impossible to miss in scrolling logs.
   *
   * @param missing - Array of missing resource entries
   * @returns Formatted banner string
   */
  static formatDevWarningBanner(missing: ResourceEntry[]): string;
}
//#endregion
export { ResourceRegistry };
//# sourceMappingURL=resource-registry.d.ts.map