# Code generated by highflame-policy-codegen. DO NOT EDIT.
# Source: schemas/guardrails/templates/templates.json
#
# Guardrails default policies and templates.
# Cedar text is loaded from package data at import time.
#
# Usage:
#   from highflame_policy.guardrails_defaults import (
#       GUARDRAILS_DEFAULTS,
#       GUARDRAILS_TEMPLATES,
#       GUARDRAILS_CATEGORIES,
#       get_guardrails_defaults_by_category,
#       get_guardrails_templates_by_category,
#       get_guardrails_template_by_id,
#   )

import json
from dataclasses import dataclass, field
from importlib.resources import files
from typing import Optional


# =============================================================================
# TYPES
# =============================================================================

# Valid Guardrails policy categories
GuardrailsCategory = str  # One of: 'security', 'privacy', 'trust_safety', 'agentic_security', 'organization'

VALID_CATEGORIES = frozenset(['security', 'privacy', 'trust_safety', 'agentic_security', 'organization'])


@dataclass(frozen=True)
class GuardrailsCategoryInfo:
    """Category metadata for UI display."""
    id: str
    name: str
    description: str


@dataclass(frozen=True)
class GuardrailsDefaultPolicy:
    """A default policy that is auto-created for new projects."""
    id: str
    name: str
    description: str
    category: str
    cedar_text: str
    severity: str
    tags: tuple[str, ...]
    is_active: bool


@dataclass(frozen=True)
class GuardrailsTemplate:
    """A policy template available for users to create from."""
    id: str
    name: str
    description: str
    category: str
    cedar_text: str
    severity: str
    tags: tuple[str, ...]


# =============================================================================
# LOAD CEDAR FILES FROM PACKAGE DATA
# =============================================================================

def _load_cedar(path: str) -> str:
    """Load a Cedar policy file from package data."""
    return (
        files('highflame_policy._schemas.guardrails.templates')
        .joinpath(path)
        .read_text(encoding='utf-8')
    )


# Default policies (one per category)
_baseline_default_cedar = _load_cedar('defaults/baseline.cedar')
_secrets_default_cedar = _load_cedar('defaults/secrets.cedar')
_injection_default_cedar = _load_cedar('defaults/injection.cedar')
_pii_default_cedar = _load_cedar('defaults/pii.cedar')
_toxicity_default_cedar = _load_cedar('defaults/toxicity.cedar')
_tool_risk_default_cedar = _load_cedar('defaults/tool_risk.cedar')
_agentic_safety_default_cedar = _load_cedar('defaults/agentic_safety.cedar')

# Additional templates
_mcp_tool_permissions_cedar = _load_cedar('mcp_tool_permissions.cedar')
_chat_assistant_security_cedar = _load_cedar('profiles/chat_assistant/security.cedar')
_chat_assistant_privacy_cedar = _load_cedar('profiles/chat_assistant/privacy.cedar')
_chat_assistant_trust_safety_cedar = _load_cedar('profiles/chat_assistant/trust_safety.cedar')
_code_agent_agentic_security_cedar = _load_cedar('profiles/code_agent/agentic_security.cedar')
_code_agent_security_cedar = _load_cedar('profiles/code_agent/security.cedar')
_data_pipeline_privacy_cedar = _load_cedar('profiles/data_pipeline/privacy.cedar')
_data_pipeline_security_cedar = _load_cedar('profiles/data_pipeline/security.cedar')
_data_pipeline_agentic_security_cedar = _load_cedar('profiles/data_pipeline/agentic_security.cedar')


# =============================================================================
# CATEGORIES
# =============================================================================

GUARDRAILS_CATEGORIES: tuple[GuardrailsCategoryInfo, ...] = (
    GuardrailsCategoryInfo(
        id='security',
        name='Security',
        description='Detect and block prompt injection, jailbreak attempts, and credential leakage',
    ),
    GuardrailsCategoryInfo(
        id='privacy',
        name='Privacy',
        description='Detect and block personally identifiable information (PII) in prompts and responses',
    ),
    GuardrailsCategoryInfo(
        id='trust_safety',
        name='Trust & Safety',
        description='Detect and block toxic, violent, hateful, sexual, or profane content',
    ),
    GuardrailsCategoryInfo(
        id='agentic_security',
        name='Agentic Security',
        description='Detect tool abuse, data exfiltration patterns, infinite loops, and budget violations',
    ),
    GuardrailsCategoryInfo(
        id='organization',
        name='Organization',
        description='Organization-wide baselines and default permit/deny policies',
    ),
)


# =============================================================================
# DEFAULT POLICIES
# =============================================================================

GUARDRAILS_DEFAULTS: tuple[GuardrailsDefaultPolicy, ...] = (
    GuardrailsDefaultPolicy(
        id='baseline-default',
        name='Baseline Permit',
        description='Permits all actions by default — threat-specific forbid policies override this when threats are detected',
        category='organization',
        cedar_text=_baseline_default_cedar,
        severity='low',
        tags=('baseline', 'permit-default', 'organization'),
        is_active=True,
    ),
    GuardrailsDefaultPolicy(
        id='secrets-default',
        name='Secrets Detection',
        description='Block content containing API keys, tokens, credentials, or other secrets',
        category='security',
        cedar_text=_secrets_default_cedar,
        severity='critical',
        tags=('secrets', 'api-keys', 'credentials', 'data-leak'),
        is_active=True,
    ),
    GuardrailsDefaultPolicy(
        id='injection-default',
        name='Injection & Jailbreak Detection',
        description='Block prompt injection, jailbreak attempts, and command injection using ML confidence scores',
        category='security',
        cedar_text=_injection_default_cedar,
        severity='high',
        tags=('injection', 'jailbreak', 'security'),
        is_active=True,
    ),
    GuardrailsDefaultPolicy(
        id='pii-default',
        name='PII Detection',
        description='Block content containing PII such as SSN, credit cards, or passport numbers in outputs',
        category='privacy',
        cedar_text=_pii_default_cedar,
        severity='high',
        tags=('pii', 'privacy', 'data-protection'),
        is_active=True,
    ),
    GuardrailsDefaultPolicy(
        id='toxicity-default',
        name='Toxicity & Content Moderation',
        description='Block toxic, violent, hateful, sexual, and profane content based on classifier scores',
        category='trust_safety',
        cedar_text=_toxicity_default_cedar,
        severity='critical',
        tags=('toxicity', 'trust-safety', 'content-moderation'),
        is_active=True,
    ),
    GuardrailsDefaultPolicy(
        id='tool-risk-default',
        name='Tool Risk',
        description='Block dangerous tool calls, shell execution, and sensitive tool usage based on risk scoring',
        category='agentic_security',
        cedar_text=_tool_risk_default_cedar,
        severity='critical',
        tags=('tools', 'agentic', 'security'),
        is_active=True,
    ),
    GuardrailsDefaultPolicy(
        id='agentic-safety-default',
        name='Agentic Safety',
        description='Block tool call loops, data exfiltration patterns, high-risk sequences, and budget violations',
        category='agentic_security',
        cedar_text=_agentic_safety_default_cedar,
        severity='high',
        tags=('agentic', 'safety', 'loops', 'exfiltration', 'budget'),
        is_active=True,
    ),
)


# =============================================================================
# ALL TEMPLATES
# =============================================================================

GUARDRAILS_TEMPLATES: tuple[GuardrailsTemplate, ...] = (
    GuardrailsTemplate(
        id='mcp-tool-permissions',
        name='MCP Tool Permissions',
        description='Per-tool access control for MCP servers — allow specific tools while denying others, exclude servers org-wide, block unverified sources',
        category='agentic_security',
        cedar_text=_mcp_tool_permissions_cedar,
        severity='high',
        tags=('mcp', 'tools', 'least-privilege', 'per-server', 'exclusion'),
    ),
    GuardrailsTemplate(
        id='chat-assistant-security',
        name='Chat Assistant — Security',
        description='Aggressive injection and jailbreak defense for customer-facing chatbots with lower thresholds',
        category='security',
        cedar_text=_chat_assistant_security_cedar,
        severity='high',
        tags=('profile', 'chat-assistant', 'injection', 'jailbreak', 'security'),
    ),
    GuardrailsTemplate(
        id='chat-assistant-privacy',
        name='Chat Assistant — Privacy',
        description='Block PII in both user inputs and assistant outputs for chat applications',
        category='privacy',
        cedar_text=_chat_assistant_privacy_cedar,
        severity='high',
        tags=('profile', 'chat-assistant', 'pii', 'privacy'),
    ),
    GuardrailsTemplate(
        id='chat-assistant-trust-safety',
        name='Chat Assistant — Trust & Safety',
        description='Strict content moderation with lower toxicity thresholds and topic restrictions for public-facing chat',
        category='trust_safety',
        cedar_text=_chat_assistant_trust_safety_cedar,
        severity='critical',
        tags=('profile', 'chat-assistant', 'toxicity', 'trust-safety', 'topics'),
    ),
    GuardrailsTemplate(
        id='code-agent-agentic-security',
        name='Code Agent — Agentic Security',
        description='Tool risk controls, shell blocking, loop detection, exfiltration prevention, and budget enforcement for coding assistants',
        category='agentic_security',
        cedar_text=_code_agent_agentic_security_cedar,
        severity='high',
        tags=('profile', 'code-agent', 'tools', 'agentic', 'exfiltration', 'budget'),
    ),
    GuardrailsTemplate(
        id='code-agent-security',
        name='Code Agent — Security',
        description='Prevent code agents from writing detected secrets to output files',
        category='security',
        cedar_text=_code_agent_security_cedar,
        severity='critical',
        tags=('profile', 'code-agent', 'secrets', 'security'),
    ),
    GuardrailsTemplate(
        id='data-pipeline-privacy',
        name='Data Pipeline — Privacy',
        description='Strict PII protection with zero-tolerance for sensitive PII types in data pipelines',
        category='privacy',
        cedar_text=_data_pipeline_privacy_cedar,
        severity='critical',
        tags=('profile', 'data-pipeline', 'pii', 'privacy', 'compliance'),
    ),
    GuardrailsTemplate(
        id='data-pipeline-security',
        name='Data Pipeline — Security',
        description='Strict secrets detection and lower injection thresholds for RAG and data processing pipelines',
        category='security',
        cedar_text=_data_pipeline_security_cedar,
        severity='critical',
        tags=('profile', 'data-pipeline', 'secrets', 'injection', 'security'),
    ),
    GuardrailsTemplate(
        id='data-pipeline-agentic-security',
        name='Data Pipeline — Agentic Security',
        description='Exfiltration prevention and tool risk controls for data processing pipelines',
        category='agentic_security',
        cedar_text=_data_pipeline_agentic_security_cedar,
        severity='critical',
        tags=('profile', 'data-pipeline', 'exfiltration', 'tools'),
    ),
)


# =============================================================================
# HELPER FUNCTIONS
# =============================================================================

def get_guardrails_defaults_by_category(category: str) -> list[GuardrailsDefaultPolicy]:
    return [d for d in GUARDRAILS_DEFAULTS if d.category == category]


def get_guardrails_templates_by_category(category: str) -> list[GuardrailsTemplate]:
    return [t for t in GUARDRAILS_TEMPLATES if t.category == category]


def get_guardrails_template_by_id(template_id: str) -> Optional[GuardrailsTemplate]:
    return next((t for t in GUARDRAILS_TEMPLATES if t.id == template_id), None)


def get_guardrails_templates_metadata_json() -> str:
    """Return the raw templates.json metadata."""
    return (
        files('highflame_policy._schemas.guardrails.templates')
        .joinpath('templates.json')
        .read_text(encoding='utf-8')
    )


__all__ = [
    # Types
    'GuardrailsCategoryInfo',
    'GuardrailsDefaultPolicy',
    'GuardrailsTemplate',
    # Data
    'GUARDRAILS_CATEGORIES',
    'GUARDRAILS_DEFAULTS',
    'GUARDRAILS_TEMPLATES',
    # Functions
    'get_guardrails_defaults_by_category',
    'get_guardrails_templates_by_category',
    'get_guardrails_template_by_id',
    'get_guardrails_templates_metadata_json',
]
