/**
 * MemoryProvider adapter contract (optional plugin — not bundled in core runtime).
 */

const PROVIDER_CONTRACT = {
  name: "string",
  methods: ["health", "search"],
  optionalMethods: ["ingest"]
};

function createMemoryProviderStub(name = "local") {
  return {
    name,
    async health() {
      return { ok: true, detail: "local fallback (HANDOFF, project files)" };
    },
    async search(_query, _scope, _limit = 5) {
      return [];
    }
  };
}

function validateMemoryProvider(provider) {
  const errors = [];
  if (!provider?.name) errors.push("provider.name required");
  if (typeof provider.health !== "function") errors.push("provider.health required");
  if (typeof provider.search !== "function") errors.push("provider.search required");
  return { valid: errors.length === 0, errors };
}

module.exports = {
  PROVIDER_CONTRACT,
  createMemoryProviderStub,
  validateMemoryProvider
};
