/**
 * Agent Pool Types - Pool configuration for controlling agent concurrency
 *
 * Agent pools provide a way to limit the maximum number of agents running
 * concurrently across one or more agent types. The dispatch daemon respects
 * pool limits when spawning agents, and pools can have configurable priority
 * for each agent type to determine spawn order when there are multiple pending
 * tasks/resources.
 *
 * Key concepts:
 * - Pool size: Maximum number of concurrent agents across all types in the pool
 * - Agent type slots: Which agent types (worker, steward) can occupy pool slots
 * - Priority scores: Per-type priority for tie-breaking when multiple tasks are ready
 *
 * @module
 */
// ============================================================================
// Validation Functions
// ============================================================================
/**
 * Valid pool name pattern: alphanumeric, hyphen, underscore
 */
const POOL_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
/**
 * Validates a pool name
 */
export function isValidPoolName(value) {
    if (typeof value !== 'string')
        return false;
    if (value.length < 1 || value.length > 64)
        return false;
    return POOL_NAME_PATTERN.test(value);
}
/**
 * Validates a pool max size
 */
export function isValidPoolSize(value) {
    if (typeof value !== 'number')
        return false;
    if (!Number.isInteger(value))
        return false;
    if (value < 1 || value > 1000)
        return false;
    return true;
}
/**
 * Validates a priority score
 */
export function isValidPriorityScore(value) {
    if (typeof value !== 'number')
        return false;
    if (!Number.isInteger(value))
        return false;
    return true;
}
/**
 * Validates a pool agent type configuration
 */
export function isValidPoolAgentTypeConfig(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const config = value;
    // Role is required and must be worker or steward (not director)
    if (config.role !== 'worker' && config.role !== 'steward')
        return false;
    // Optional fields validation
    if (config.workerMode !== undefined) {
        if (config.workerMode !== 'ephemeral' && config.workerMode !== 'persistent') {
            return false;
        }
    }
    if (config.stewardFocus !== undefined) {
        const validFocuses = ['merge', 'health', 'reminder', 'ops', 'docs'];
        if (!validFocuses.includes(config.stewardFocus)) {
            return false;
        }
    }
    if (config.priority !== undefined && !isValidPriorityScore(config.priority)) {
        return false;
    }
    if (config.maxSlots !== undefined && !isValidPoolSize(config.maxSlots)) {
        return false;
    }
    return true;
}
/**
 * Validates a pool configuration
 */
export function isValidPoolConfig(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const config = value;
    if (!isValidPoolName(config.name))
        return false;
    if (!isValidPoolSize(config.maxSize))
        return false;
    if (config.agentTypes !== undefined) {
        if (!Array.isArray(config.agentTypes))
            return false;
        for (const agentType of config.agentTypes) {
            if (!isValidPoolAgentTypeConfig(agentType))
                return false;
        }
    }
    return true;
}
// ============================================================================
// Type Guards
// ============================================================================
/**
 * Type guard to check if a value is an AgentPool
 */
export function isAgentPool(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const pool = value;
    return (typeof pool.id === 'string' &&
        typeof pool.config === 'object' &&
        pool.config !== null &&
        typeof pool.status === 'object' &&
        pool.status !== null &&
        typeof pool.createdAt !== 'undefined' &&
        typeof pool.createdBy === 'string');
}
// ============================================================================
// Constants
// ============================================================================
/**
 * Default pool configuration values
 */
export const POOL_DEFAULTS = {
    /** Default pool max size */
    maxSize: 5,
    /** Default enabled status */
    enabled: true,
    /** Default priority for agent types */
    defaultPriority: 0,
};
/**
 * Pool metadata key for storing pool config in Entity metadata
 */
export const POOL_METADATA_KEY = 'agentPool';
//# sourceMappingURL=agent-pool.js.map