/**
 * Factory Functions for Brainfish API Documentation
 * 
 * Creates instances of BrainfishCollection and BrainfishRESTRequest
 * with proper defaults and unique IDs.
 */ /**
 * Generates a URL-friendly slug from a string
 * Converts to lowercase, replaces spaces and special chars with hyphens
 */ function slugify(str) {
    return str.toLowerCase().replace(/[{}]/g, '') // Remove braces from path params
    .replace(/[^a-z0-9]+/g, '-') // Replace non-alphanumeric with hyphens
    .replace(/^-+|-+$/g, '') // Remove leading/trailing hyphens
    .replace(/-+/g, '-') // Collapse multiple hyphens
    ;
}
/**
 * Generates a human-readable, deterministic ID for requests
 * Uses operationId if available, otherwise method + path
 */ function generateRequestId(method, path, operationId) {
    if (operationId) {
        // Use operationId directly (it's already unique per spec)
        return slugify(operationId);
    }
    // Generate from method + path: "get-users-id" for "GET /users/{id}"
    const pathSlug = slugify(path);
    return `${method.toLowerCase()}-${pathSlug}`;
}
/**
 * Generates a unique ID for collections
 * If a seed is provided, generates a deterministic slug-based ID
 */ function generateCollectionId(name) {
    if (name) {
        return `coll-${slugify(name)}`;
    }
    return `coll_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
/**
 * Creates a BrainfishRESTRequest with defaults
 * Generates human-readable, deterministic IDs based on operationId or method+path
 */ export function makeBrainfishRESTRequest(request) {
    // Extract path from endpoint (remove base URL)
    const path = request.endpoint ? request.endpoint.replace(/^https?:\/\/[^/]+/, '') || '/' : '/';
    // Generate human-readable ID
    const id = generateRequestId(request.method || 'GET', path, request.operationId);
    return {
        id,
        name: request.name || 'Untitled Request',
        description: request.description ?? null,
        method: request.method || 'GET',
        endpoint: request.endpoint || '',
        params: request.params || [],
        headers: request.headers || [],
        auth: request.auth || {
            authType: 'none',
            authActive: true
        },
        body: request.body || {
            contentType: null,
            body: null
        },
        requestVariables: request.requestVariables || [],
        responses: request.responses || {},
        tags: request.tags || []
    };
}
/**
 * Creates a BrainfishCollection with defaults
 * If name is provided, generates a deterministic ID
 */ export function makeBrainfishCollection(collection) {
    return {
        id: generateCollectionId(collection.name),
        name: collection.name || 'Untitled Collection',
        description: collection.description ?? null,
        folders: collection.folders || [],
        requests: collection.requests || [],
        variables: collection.variables || [],
        auth: collection.auth || {
            authType: 'inherit',
            authActive: true
        },
        headers: collection.headers || []
    };
}
/**
 * Creates a default BrainfishRESTRequest
 */ export function getDefaultBrainfishRESTRequest() {
    return makeBrainfishRESTRequest({
        name: 'Untitled Request',
        description: null,
        method: 'GET',
        endpoint: '',
        params: [],
        headers: [],
        auth: {
            authType: 'none',
            authActive: true
        },
        body: {
            contentType: null,
            body: null
        },
        requestVariables: [],
        responses: {},
        tags: []
    });
}
/**
 * Creates a default BrainfishCollection
 */ export function getDefaultBrainfishCollection() {
    return makeBrainfishCollection({
        name: 'Untitled Collection',
        description: null,
        folders: [],
        requests: [],
        variables: [],
        auth: {
            authType: 'inherit',
            authActive: true
        },
        headers: []
    });
}
/**
 * Creates a BrainfishRESTResponseOriginalRequest
 */ export function makeBrainfishRESTResponseOriginalRequest(request) {
    return {
        name: request.name,
        method: request.method,
        endpoint: request.endpoint,
        params: request.params,
        headers: request.headers,
        body: request.body,
        auth: request.auth,
        requestVariables: request.requestVariables
    };
}
