import { MeshData } from '../meshdata/index';
import * as Types from '../../types';
import { ProviderConfig, ProvidersConfig } from '../../types/provider';
/**
 * MeshOS is an abstract base class for schema-driven entity management within the Mesh network.
 * It provides a foundation for defining custom entities.
 * By subclassing MeshOS, you can create entities with specific schemas and behaviors, enabling
 * structured data storage, retrieval, and transactional workflows.
 *
 * ### Subclassing MeshOS
 *
 * Standard CRUD methods are included and use your provided schema to
 * fields to return in the response: create, retrieve, update, delete.
 *
 * Search methods are included and use your provided schema to
 * fields to return in the response: count, find, aggregate.
 *
 * Implement other methods as needed for the entity's
 * functionality; For example, subclass/override methods like `create`
 * to also spawn a transactional workflow
 *
 * @example
 * ```typescript
 * import { MeshOS } from '@hotmeshio/hotmesh';
 * import { Types } from '@hotmeshio/hotmesh';
 * import { schema } from './schema'; // Import your schema
 * import * as workflows from './workflows';
 *
 * class Widget extends MeshOS {
 *
 *   //Subclass the `connect` method to connect workers and
 *   // hooks (optional) when the container starts
 *   async connect() {
 *     await this.meshData.connect({
 *       entity: this.getEntity(),
 *       //the `target widget workflow` runs as a transaction
 *       target: function() {
 *         return { hello: 'world' };
 *       },
 *       options: {
 *         namespace: this.getNamespace(),
 *         taskQueue: this.getTaskQueue(),
 *       },
 *     });
 *   }
 *
 *   // subclass the `create` method to start a transactional
 *   // workflow; use the options/search field to set default
 *   // record data `{ ...input}` and invoke the `target widget workflow`
 *   async create(input: Types.StringAnyType): Promise<Types.StringStringType> {
 *     return await this.meshData.exec<Types.StringStringType>({
 *       entity: this.getEntity(),
 *       args: [{ ...input }],
 *       options: {
 *         id: input.id,
 *         ttl: '6 months',
 *         taskQueue: this.getTaskQueue(),
 *         namespace: this.getNamespace(),
 *         search: { data: { ...input }},
 *        },
 *     });
 *   }
 * }
 * ```
 *
 * ### Defining the Schema
 *
 * The schema defines the data model for your entity and is used for indexing and searching within the mesh network.
 * Each field in the schema specifies the data type, whether it's required, and other indexing options.
 *
 * Here's an example of a schema (`schema.ts`):
 *
 * ```typescript
 * import { Types } from '@hotmeshio/hotmesh';
 *
 * export const schema: Types.WorkflowSearchSchema = {
 *   /**
 *    * Unique identifier for the widget, including the entity prefix.
 *    *\/
 *   id: {
 *     type: 'TAG',
 *     primitive: 'string',
 *     required: true,
 *     examples: ['H56789'],
 *   },
 *   /**
 *    * entity type
 *    *\/
 *   $entity: {
 *     type: 'TAG',
 *     primitive: 'string',
 *     required: true,
 *     examples: ['widget'],
 *   },
 *   /**
 *    * Field indicating whether the widget is active ('y') or pruned ('n').
 *    *\/
 *   active: {
 *     type: 'TAG',
 *     primitive: 'string',
 *     required: true,
 *     examples: ['y', 'n'],
 *   },
 *   // ... other fields as needed
 * };
 * ```
 *
 * In your entity class (`Widget`), you use this schema in the
 * `getSearchOptions` method to define how your entity's data
 * is indexed and searched.
 */
declare abstract class MeshOS {
    meshData: MeshData;
    connected: boolean;
    entity: string;
    namespace: string;
    schema: Types.WorkflowSearchSchema;
    taskQueue: string;
    static databases: Record<string, Types.DB>;
    static namespaces: Types.Namespaces;
    static entities: Record<string, Types.Entity>;
    static schemas: Record<string, Types.WorkflowSearchSchema>;
    static profiles: Types.Profiles;
    static classes: Record<string, typeof MeshOS>;
    static logger: Types.ILogger;
    /**
     * Instances of MeshOS are typically initialized as a set, using a manifest.json
     * file that describes statically the fully set names, passwords, entities, etc.
     * The static init method is invoked to start this process (typically at server
     * startup).
     */
    constructor(providerConfig: ProviderConfig | ProvidersConfig, namespace: string, entity: string, taskQueue: string, schema: Types.WorkflowSearchSchema);
    /**
     * Return entity (e.g, book, library, user)
     */
    getEntity(): string;
    /**
     * Get Search options (initializes the search index, specific to the backend provider)
     */
    getSearchOptions(): Types.WorkflowSearchOptions;
    /**
     * Speficy a more-specific task queue than the default queue (v1, v1priority, v2, acmecorp, etc)
     */
    getTaskQueue(): string;
    /**
     * Initialize MeshData instance (this backs/supports the class
     * --the true provider of functionality)
     */
    private initializeMeshData;
    /**
     * Default target function
     */
    protected defaultTargetFn(): Promise<string>;
    /**
     * Get namespace
     */
    getNamespace(): string;
    /**
     * Get schema
     */
    getSchema(): Types.WorkflowSearchSchema;
    /**
     * Connect to the database
     */
    connect(): Promise<void>;
    /**
     * Create the search index
     */
    index(): Promise<void>;
    /**
     * Shutdown all connections
     */
    static shutdown(): Promise<void>;
    /**
     * Get index name
     */
    getIndexName(): string;
    /**
     * Create the data record
     * NOTE: subclasses should override this method (or create
     * an alternate method) for invoking a workflow when
     * creating the record.
     */
    create(body: Record<string, any>): Promise<Types.StringStringType>;
    /**
     * Retrieve the record data
     */
    retrieve(id: string, sparse?: boolean): Promise<Types.StringStringType>;
    /**
     * Update the record data
     */
    update(id: string, body: Record<string, any>): Promise<Types.StringStringType>;
    /**
     * Delete the record/workflow
     */
    delete(id: string): Promise<boolean>;
    /**
     * Find matching records
     */
    find(query?: {
        field: string;
        is: '=' | '[]' | '>=' | '<=';
        value: string;
    }[], start?: number, size?: number): Promise<{
        count: number;
        query: string;
        data: Types.StringStringType[];
    }>;
    /**
     * Count matching entities
     */
    count(query: {
        field: string;
        is: '=' | '[]' | '>=' | '<=';
        value: string;
    }[]): Promise<number>;
    /**
     * Aggregate matching entities
     */
    aggregate(filter?: {
        field: string;
        is: '=' | '[]' | '>=' | '<=';
        value: string;
    }[], apply?: {
        expression: string;
        as: string;
    }[], rows?: string[], columns?: string[], reduce?: {
        operation: string;
        as: string;
        property?: string;
    }[], sort?: {
        field: string;
        order: 'ASC' | 'DESC';
    }[], start?: number, size?: number): Promise<{
        count: number;
        query: string;
        data: Types.StringStringType[];
    }>;
    /**
     * Build aggregate command
     */
    private buildAggregateCommand;
    /**
     * Build filter command
     */
    private buildFilterCommand;
    /**
     * Instance initializer
     */
    init(search?: boolean): Promise<void>;
    /**
     * Register a database
     */
    static registerDatabase(id: string, config: Types.DB): void;
    /**
     * Register a namespace
     */
    static registerNamespace(id: string, config: Types.Namespace): void;
    /**
     * Register an entity
     */
    static registerEntity(id: string, config: Types.Entity): void;
    /**
     * Register a schema
     */
    static registerSchema(id: string, schema: Types.WorkflowSearchSchema): void;
    /**
     * Register a profile
     */
    static registerProfile(id: string, config: Types.Profile): void;
    /**
     * Register a class
     */
    static registerClass(id: string, entityClass: typeof MeshOS): void;
    /**
     * Initialize profiles
     */
    static init(p?: Types.Profiles): Promise<void>;
    /**
     * Find entity instance
     */
    static findEntity(database: string, namespace: string, entity: string): Types.EntityInstanceTypes | undefined;
    /**
     * Find schemas
     */
    static findSchemas(database: string, ns: string): Record<string, Types.WorkflowSearchSchema>;
    /**
     * Serialize profiles to JSON
     */
    static toJSON(p?: Types.Profiles): any;
    workflow: {};
}
export { MeshOS };
