/**
 * IMemoryService — Contract const for memory persistence and search.
 *
 * This ONE object is the type, the intent, the validator, and the
 * $introspect response. Pass it to resolve() to get a typed proxy.
 *
 * Reference implementation for the service contracts pattern.
 */

import type { ServiceContract } from '../ServiceContract';

export const IMemoryService: ServiceContract = {
  id: 'memory',
  description: 'Memory persistence and hybrid search',
  ops: {
    'memory.save': {
      description: 'Save a memory record',
      payload: {
        content: { type: 'string', required: true, description: 'Text to remember' },
        tags: { type: 'string[]', required: false, description: 'Categorization tags' },
      },
      response: {
        ok: { type: 'boolean' },
        id: { type: 'string', description: 'Saved record ID' },
      },
      errors: [
        { code: 'MISSING_CONTENT', description: 'content is required' },
      ],
    },
    'memory.search': {
      description: 'Search memories by text query',
      payload: {
        query: { type: 'string', required: true, description: 'Search text' },
        limit: { type: 'number', required: false, description: 'Max results (default 50)' },
      },
      response: {
        ok: { type: 'boolean' },
        rows: { type: 'MemoryRecord[]', description: 'Ranked results' },
      },
    },
    'memory.get': {
      description: 'Get a memory record by ID',
      payload: {
        id: { type: 'string', required: true },
      },
      response: {
        ok: { type: 'boolean' },
        record: { type: 'MemoryRecord' },
      },
    },
    'memory.history': {
      description: 'Recent memories for this actor',
      payload: {
        limit: { type: 'number', required: false, description: 'Max results' },
      },
      response: {
        ok: { type: 'boolean' },
        records: { type: 'MemoryRecord[]' },
      },
    },
  },
};
