# Grubtech Integration Code Templates

This directory contains code templates for generating integration code snippets.

## Directory Structure

```
templates/
├── {operation}/
│   ├── {language}.template
│   └── ...
```

## Supported Operations

- `authenticate` - API authentication
- `create_menu` - Menu synchronization
- `receive_order` - Order webhook endpoint
- `update_order_status` - Order status updates
- `update_item_availability` - Item availability updates

## Supported Languages

- `typescript` - TypeScript/Node.js
- `python` - Python 3.8+
- `java` - Java 17+ with Spring Boot
- `curl` - cURL commands

## Template Format

### File Naming

Templates must follow the naming convention: `{language}.template`

Example: `typescript.template`, `python.template`

### Variable Placeholders

Use double curly braces for variables: `{{VARIABLE_NAME}}`

Example:
```typescript
const API_KEY = '{{API_KEY}}';
const PARTNER_ID = '{{PARTNER_ID}}';
```

### Metadata (Optional)

Include metadata in header comments using JSDoc-style tags:

```typescript
/**
 * @description Grubtech API Authentication - TypeScript
 * @author Grubtech Integration Team
 * @version 1.0.0
 */
```

Supported metadata tags:
- `@description` - Template description
- `@author` - Template author
- `@version` - Template version

### Template Requirements

1. **Syntactically Valid**: Templates must be valid code in their language
2. **Comments**: Include explanatory comments for each section
3. **Error Handling**: Include error handling examples
4. **Complete Examples**: Provide runnable code with example data
5. **Placeholders**: Use clear, descriptive placeholder names

## Adding New Templates

1. Create operation directory: `templates/{operation}/`
2. Add template file: `{language}.template`
3. Include header metadata
4. Add variable placeholders using `{{VARIABLE}}`
5. Test syntax validity
6. Update this README

## Template Loader

Templates are loaded via the `TemplateLoader` class:

```typescript
import { TemplateLoader } from './tools/template-loader.js';

const loader = new TemplateLoader();

// Load template
const template = await loader.loadTemplate('authenticate', 'typescript');

// Substitute variables
const code = loader.substituteVariables(template, {
  API_KEY: 'my-key',
  PARTNER_ID: 'partner-123',
});
```
