import { ActionKeyword, detectActions } from '../constants/actions';

interface TableGenerationPromptParams {
    prompt: string;
    context?: string;
    keywords?: string[];
    id?: string;
    tableSchema?: {
        name: string;
        fields: Array<{
            name: string;
            type: string;
            description?: string;
        }>;
    };
}

export const generateTablePrompt = (params: TableGenerationPromptParams): string => {
    const {
        prompt,
        context = 'General information',
        keywords = [],
        id = 'auto-generated',
        tableSchema
    } = params;

    const detectedActions = detectActions(prompt, keywords);

    return `Create a table with data about: ${prompt}
Context: ${context}
Keywords: ${keywords.join(', ') || 'None specified'}
${tableSchema ? `
Table Schema:
Name: ${tableSchema.name}
Fields:
${tableSchema.fields.map(f => `- ${f.name} (${f.type})${f.description ? `: ${f.description}` : ''}`).join('\n')}
` : ''}

Detected Actions:
${detectedActions.map(action => `- ${action.description}`).join('\n')}

Return ONLY a JSON object in this format:
{
    "columns": [
        {"field": "column1", "header": "Column 1"},
        {"field": "column2", "header": "Column 2"}
    ],
    "data": [
        {"column1": "value1", "column2": "value2"},
        {"column1": "value3", "column2": "value4"}
    ],
    "metadata": {
        "id": "${id}",
        "keywords": ${JSON.stringify(keywords)},
        "context": "${context}",
        "timestamp": "${new Date().toISOString()}",
        "actions": ${JSON.stringify(detectedActions)}
    }
}

Rules:
1. Return ONLY the JSON object, no explanations
2. Make sure field names in data match column fields exactly
3. Choose appropriate column names based on the topic
4. Include at least 5 rows of data
5. Ensure all data is relevant to the context and keywords
6. Format dates in ISO format if present
7. Use consistent data types within columns
8. If table schema is provided, strictly follow the field names and types
9. Ensure all required fields from the schema are present in the data
10. Format the data according to the specified types in the schema
11. For multiple actions, prioritize the first action mentioned
12. When creating endpoints, include all related actions in the endpoint description
13. For row click actions, use the 'view' action type`;
}; 