---
# ============================================================================
# Weaver Registry Setup Generator for clnrm v2.0
# ============================================================================
# Generates Weaver registry structure from RDF CLI definitions
# Usage: ggen template generate -t templates/clnrm/weaver-registry.tmpl -r docs/clnrm-cli-v2.ttl -o registry/
# ============================================================================

sparql:
  # Project metadata
  project_info: |
    PREFIX cli: <http://ggen.dev/schema/cli#>
    
    SELECT ?name ?version ?description
    WHERE {
      ?project a cli:CliProject ;
               cli:hasName ?name ;
               cli:hasVersion ?version ;
               cli:hasDescription ?description .
    }
  
  # Extract all span definitions
  spans: |
    PREFIX cli: <http://ggen.dev/schema/cli#>
    PREFIX cnv: <http://ggen.dev/schema/clap-noun-verb#>
    
    SELECT ?nounName ?verbName ?verbDesc ?spanName
    WHERE {
      ?project cli:hasNoun ?noun .
      ?noun cnv:nounName ?nounName ;
            cnv:hasVerb ?verb .
      ?verb cnv:verbName ?verbName ;
            cnv:verbDescription ?verbDesc .
      BIND(CONCAT("{{ sparql_first(results=sparql_results.project_info, column='name') }}.", ?nounName, ".", ?verbName) AS ?spanName)
    }
    ORDER BY ?nounName ?verbName

---

{# FILE: registry/README.md #}
# Weaver Registry for {{ sparql_first(results=sparql_results.project_info, column='name') }} v{{ sparql_first(results=sparql_results.project_info, column='version') }}

{{ sparql_first(results=sparql_results.project_info, column='description') }}

This registry contains semantic convention schemas for Weaver validation of {{ sparql_first(results=sparql_results.project_info, column='name') }} telemetry.

## Structure

```
registry/
├── README.md           # This file
├── cli/                # CLI command schemas
│   ├── test.yaml      # Test command spans
│   ├── service.yaml    # Service command spans
│   ├── collector.yaml # Collector command spans
│   ├── project.yaml    # Project command spans
│   ├── report.yaml     # Report command spans
│   └── health.yaml     # Health command spans
└── manifest.yaml       # Registry manifest (auto-generated by Weaver)
```

## Usage

1. **Initialize Weaver registry**:
   ```bash
   weaver registry init --path registry/
   ```

2. **Run live-check**:
   ```bash
   weaver registry live-check \
     --registry registry/ \
     --endpoint http://localhost:4317/v1/traces
   ```

## Expected Spans

{% for span in sparql_results.spans %}
- `{{ span.spanName }}` - {{ span.verbDesc }}
{% endfor %}

{# FILE: registry/cli/test.yaml #}
# Test command spans for {{ sparql_first(results=sparql_results.project_info, column='name') }}
# Generated from RDF CLI definition

schema_id: "clnrm:test"
schema_version: "1.0.0"
description: "Spans emitted by test commands"

spans:
{% for span in sparql_results.spans %}
{% if span.nounName == "test" %}
  - name: "{{ span.spanName }}"
    description: "{{ span.verbDesc }}"
    attributes:
      - name: "clnrm.test.name"
        type: "string"
        description: "Test name"
        required: false
      - name: "clnrm.test.result"
        type: "string"
        description: "Test result (pass, fail, skip)"
        required: false
      - name: "clnrm.test.duration_ms"
        type: "int64"
        description: "Test duration in milliseconds"
        required: false
{% endif %}
{% endfor %}

{# FILE: registry/cli/service.yaml #}
# Service command spans for {{ sparql_first(results=sparql_results.project_info, column='name') }}
# Generated from RDF CLI definition

schema_id: "clnrm:service"
schema_version: "1.0.0"
description: "Spans emitted by service management commands"

spans:
{% for span in sparql_results.spans %}
{% if span.nounName == "service" %}
  - name: "{{ span.spanName }}"
    description: "{{ span.verbDesc }}"
    attributes:
      - name: "service.name"
        type: "string"
        description: "Service name"
        required: true
      - name: "service.type"
        type: "string"
        description: "Service type (generic_container, surrealdb, etc.)"
        required: false
{% endif %}
{% endfor %}

{# FILE: registry/cli/collector.yaml #}
# Collector command spans for {{ sparql_first(results=sparql_results.project_info, column='name') }}
# Generated from RDF CLI definition

schema_id: "clnrm:collector"
schema_version: "1.0.0"
description: "Spans emitted by OpenTelemetry collector commands"

spans:
{% for span in sparql_results.spans %}
{% if span.nounName == "collector" %}
  - name: "{{ span.spanName }}"
    description: "{{ span.verbDesc }}"
    attributes:
      - name: "collector.image"
        type: "string"
        description: "Collector Docker image"
        required: false
      - name: "collector.otlp_port"
        type: "int64"
        description: "OTLP port"
        required: false
{% endif %}
{% endfor %}

{# FILE: registry/cli/project.yaml #}
# Project command spans for {{ sparql_first(results=sparql_results.project_info, column='name') }}
# Generated from RDF CLI definition

schema_id: "clnrm:project"
schema_version: "1.0.0"
description: "Spans emitted by project management commands"

spans:
{% for span in sparql_results.spans %}
{% if span.nounName == "project" %}
  - name: "{{ span.spanName }}"
    description: "{{ span.verbDesc }}"
    attributes:
      - name: "project.path"
        type: "string"
        description: "Project path"
        required: false
      - name: "config.generated"
        type: "boolean"
        description: "Whether config was generated"
        required: false
{% endif %}
{% endfor %}

{# FILE: registry/cli/report.yaml #}
# Report command spans for {{ sparql_first(results=sparql_results.project_info, column='name') }}
# Generated from RDF CLI definition

schema_id: "clnrm:report"
schema_version: "1.0.0"
description: "Spans emitted by report generation commands"

spans:
{% for span in sparql_results.spans %}
{% if span.nounName == "report" %}
  - name: "{{ span.spanName }}"
    description: "{{ span.verbDesc }}"
    attributes:
      - name: "report.format"
        type: "string"
        description: "Report format (html, markdown, json, pdf)"
        required: false
      - name: "report.input"
        type: "string"
        description: "Input file path"
        required: false
      - name: "report.output"
        type: "string"
        description: "Output file path"
        required: false
{% endif %}
{% endfor %}

{# FILE: registry/cli/health.yaml #}
# Health command spans for {{ sparql_first(results=sparql_results.project_info, column='name') }}
# Generated from RDF CLI definition

schema_id: "clnrm:health"
schema_version: "1.0.0"
description: "Spans emitted by health check commands"

spans:
{% for span in sparql_results.spans %}
{% if span.nounName == "health" %}
  - name: "{{ span.spanName }}"
    description: "{{ span.verbDesc }}"
    attributes:
      - name: "health.overall"
        type: "string"
        description: "Overall health status"
        required: true
      - name: "health.checks_passed"
        type: "int64"
        description: "Number of checks passed"
        required: false
      - name: "health.checks_failed"
        type: "int64"
        description: "Number of checks failed"
        required: false
{% endif %}
{% endfor %}

{# FILE: registry/init.sh #}
#!/bin/bash
# Weaver registry initialization script
# Generated from RDF CLI definition

set -e

echo "Initializing Weaver registry for {{ sparql_first(results=sparql_results.project_info, column='name') }}..."

# Create registry directory structure
mkdir -p registry/cli

# Initialize Weaver registry (if weaver CLI is available)
if command -v weaver &> /dev/null; then
    echo "Running weaver registry init..."
    weaver registry init --path registry/ || echo "Warning: weaver registry init failed (registry may already exist)"
else
    echo "Warning: weaver CLI not found. Install with: cargo install weaver-cli"
    echo "Registry structure created manually."
fi

echo "✅ Registry initialized at: registry/"
echo ""
echo "Next steps:"
echo "  1. Review generated schema files in registry/cli/"
echo "  2. Run: weaver registry live-check --registry registry/ --endpoint http://localhost:4317/v1/traces"
echo "  3. Integrate with {{ sparql_first(results=sparql_results.project_info, column='name') }} test execution"

