// engine/spec-templates/templates-api-ui.ts — REST API endpoint + UI form templates.
// Extracted from catalog.ts to keep file sizes within limits.
/** REST API endpoint spec template. */
export const REST_API_ENDPOINT_TEMPLATE = {
    id: 'rest-api-endpoint',
    name: 'REST API Endpoint',
    category: 'api',
    description: 'A single REST endpoint with validation, error handling, and documentation.',
    tags: ['api', 'rest', 'endpoint', 'openapi'],
    complexityScore: 'S',
    estimationBase: {
        hoursMin: 4,
        hoursMax: 8,
        notes: 'Single endpoint with validation and error handling',
    },
    criteria: [
        { id: 'AC-1', title: 'Request validation', required: true },
        { id: 'AC-2', title: 'Core business logic', required: true },
        { id: 'AC-3', title: 'Response contract', required: true },
        { id: 'AC-4', title: 'Error handling', required: true },
        { id: 'AC-5', title: 'Idempotency', required: false },
        { id: 'AC-6', title: 'Observability', required: false },
    ],
    variables: [
        {
            key: 'EndpointName',
            label: 'Endpoint name',
            description: 'Short descriptive name for this endpoint',
            example: 'Submit Order',
            required: true,
        },
        {
            key: 'HttpMethod',
            label: 'HTTP Method',
            description: 'HTTP method: GET, POST, PUT, PATCH, DELETE',
            example: 'POST',
            required: true,
        },
        {
            key: 'Path',
            label: 'URL path',
            description: 'The URL path for this endpoint',
            example: '/orders/submit',
            required: true,
        },
    ],
    huTemplate: `# HU: REST API Endpoint — {{EndpointName}}

## User Story
As an API consumer, I want a reliable {{HttpMethod}} {{Path}} endpoint so that I can {{EndpointName}} without client-side workarounds.

## Acceptance Criteria

### AC-1: Request validation
- [ ] Input schema validated at the boundary
- [ ] Invalid requests return 422 with structured error messages
- [ ] Content-Type header checked when applicable

### AC-2: Core business logic
- [ ] {{EndpointName}} logic is encapsulated in a dedicated use-case function
- [ ] Side effects (emails, notifications, jobs) are isolated and testable

### AC-3: Response contract
- [ ] Success response follows the API response envelope convention
- [ ] HTTP status codes match the operation semantics
- [ ] Response schema is documented (OpenAPI or equivalent)

### AC-4: Error handling
- [ ] All error paths return structured JSON (not stack traces)
- [ ] 404 returned for missing resources
- [ ] 409 returned for conflicts
- [ ] 500 never leaks internal details

### AC-5: Idempotency (if applicable)
- [ ] Idempotency key header supported for non-idempotent operations
- [ ] Duplicate requests handled gracefully

### AC-6: Observability
- [ ] Endpoint logged with method, path, status, latency
- [ ] Errors reported to the monitoring system
`,
    fichaTecnicaTemplate: `# FICHA TÉCNICA: REST API Endpoint — {{EndpointName}}

## Affected Files
- handlers/{{Path}} (route handler)
- use-cases/{{EndpointName}} (business logic)
- validators/{{EndpointName}}-input
- openapi/paths/{{Path}} (documentation)

## Types / Entities
- \`{{EndpointName}}Input\`: validated request payload
- \`{{EndpointName}}Output\`: response body shape
- \`ApiError\`: code, message, details[]

## Risks
- Missing idempotency for mutation → duplicate side effects
- Unbounded response size → add pagination or field projection
- Missing auth guard → unauthorized access

## Estimation (rough)
- Dev: 4–8 hours
- Review: 1–2 hours
- Difficulty: 2/5
`,
    progressTemplate: `# PROGRESS: REST API Endpoint — {{EndpointName}}

## Status: draft

## Criteria
- [ ] AC-1: Request validation
- [ ] AC-2: Core business logic
- [ ] AC-3: Response contract
- [ ] AC-4: Error handling
- [ ] AC-5: Idempotency
- [ ] AC-6: Observability
`,
};
/** UI Form spec template. */
export const UI_FORM_TEMPLATE = {
    id: 'ui-form',
    name: 'UI Form',
    category: 'ui',
    description: 'Interactive form with validation, error display, and accessibility.',
    tags: ['ui', 'form', 'ux', 'accessibility', 'validation'],
    complexityScore: 'S',
    estimationBase: {
        hoursMin: 4,
        hoursMax: 10,
        notes: 'Form with client-side validation and accessibility',
    },
    criteria: [
        { id: 'AC-1', title: 'Field validation', required: true },
        { id: 'AC-2', title: 'Submit behavior', required: true },
        { id: 'AC-3', title: 'Accessibility', required: true },
        { id: 'AC-4', title: 'Responsive design', required: false },
        { id: 'AC-5', title: 'Reset and cancel', required: false },
    ],
    variables: [
        {
            key: 'FormName',
            label: 'Form name',
            description: 'Name of the form (e.g. Registration, Checkout, Contact)',
            example: 'Registration',
            required: true,
        },
    ],
    huTemplate: `# HU: {{FormName}} Form

## User Story
As a user, I want to fill out the {{FormName}} form with clear guidance so that I can complete the action without confusion.

## Acceptance Criteria

### AC-1: Field validation
- [ ] Required fields marked visually
- [ ] Validation runs on blur and on submit
- [ ] Error messages appear adjacent to invalid fields
- [ ] Valid fields show positive feedback

### AC-2: Submit behavior
- [ ] Form is disabled (loading state) during submission
- [ ] Success state shown after successful submission
- [ ] Errors from the API are displayed inline

### AC-3: Accessibility
- [ ] All inputs have visible labels
- [ ] Error messages linked via aria-describedby
- [ ] Form navigable via keyboard (Tab, Enter, Escape)
- [ ] Screen reader announces validation errors

### AC-4: Responsive design
- [ ] Form renders correctly on mobile, tablet, and desktop
- [ ] Touch targets meet minimum size (44x44 px)

### AC-5: Reset and cancel
- [ ] Reset clears all fields and removes error state
- [ ] Cancel navigates away without data loss warning if form is pristine
- [ ] Cancel shows confirmation dialog if form has unsaved changes
`,
    fichaTecnicaTemplate: `# FICHA TÉCNICA: {{FormName}} Form

## Affected Files
- components/{{FormName}}Form
- hooks/use{{FormName}}Form (form state, validation)
- api/{{FormName}}-client (submission)
- i18n/{{FormName}}-form.json (strings)

## Types / Entities
- \`{{FormName}}FormValues\`: all field values
- \`{{FormName}}FormErrors\`: per-field error messages
- \`{{FormName}}FormState\`: idle | submitting | success | error

## Risks
- Missing server-side validation mirror → inconsistent UX
- Missing loading state → double submissions
- Missing ARIA attributes → accessibility failures

## Estimation (rough)
- Dev: 4–10 hours
- Review: 1–2 hours
- Difficulty: 2/5
`,
    progressTemplate: `# PROGRESS: {{FormName}} Form

## Status: draft

## Criteria
- [ ] AC-1: Field validation
- [ ] AC-2: Submit behavior
- [ ] AC-3: Accessibility
- [ ] AC-4: Responsive design
- [ ] AC-5: Reset and cancel
`,
};
//# sourceMappingURL=templates-api-ui.js.map