from functools import wraps

# Dictionary to hold registered capability templates
templates = {}

def capability_template(cap_type):
    def decorator(func):
        templates[cap_type] = func
        return func
    return decorator

class TemplateManager:
    def __init__(self):
        self.templates = templates
    
    def build_capability(self, capability_id, cap_type, **kwargs):
        if cap_type not in self.templates:
            raise ValueError(f"Template for {cap_type} does not exist.")
        # Apply the template with provided parameters
        return self.templates[cap_type](capability_id, **kwargs)

# Example templates for different capabilities

@capability_template('web_service')
def web_service_template(capability_id, port=8000, framework='Flask'):
    """Template for building web services."""
    return {
        'id': capability_id,
        'type': 'web_service',
        'config': {
            'port': port,
            'framework': framework
        }
    }

@capability_template('database_connection')
def database_connection_template(capability_id, db_type='PostgreSQL', host='localhost'):
    """Template for database connections."""
    return {
        'id': capability_id,
        'type': 'database_connection',
        'config': {
            'db_type': db_type,
            'host': host
        }
    }

# Usage example:
if __name__ == "__main__":
    manager = TemplateManager()
    
    # Build a web service using the template
    web_service = manager.build_capability('web_api', 'web_service', port=8080)
    print("Web Service:", web_service)
    
    # Build a database connection using the template
    db_connection = manager.build_capability('db_connection_1', 'database_connection')
    print("\nDatabase Connection:", db_connection)