# Code generated by highflame-policy-codegen. DO NOT EDIT.
# Source: schemas/sentry/templates/templates.json
#
# Sentry default policies and templates.
# Cedar text is loaded from package data at import time.
#
# Usage:
#   from highflame_policy.sentry_defaults import (
#       SENTRY_DEFAULTS,
#       SENTRY_TEMPLATES,
#       SENTRY_CATEGORIES,
#       get_sentry_defaults_by_category,
#       get_sentry_templates_by_category,
#       get_sentry_template_by_id,
#   )

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


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

# Valid Sentry policy categories
SentryCategory = str  # One of: 'pii', 'semantic', 'content_safety', 'file_safety', 'organization'

VALID_CATEGORIES = frozenset(['pii', 'semantic', 'content_safety', 'file_safety', 'organization'])


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


@dataclass(frozen=True)
class SentryDefaultPolicy:
    """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 SentryTemplate:
    """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.sentry.templates')
        .joinpath(path)
        .read_text(encoding='utf-8')
    )


# Default policies (one per category)
_sentry_baseline_default_cedar = _load_cedar('defaults/baseline.cedar')
_sentry_semantic_default_cedar = _load_cedar('defaults/semantic.cedar')
_sentry_content_safety_default_cedar = _load_cedar('defaults/content_safety.cedar')

# Additional templates
_sentry_pii_default_cedar = _load_cedar('defaults/pii.cedar')
_sentry_file_safety_default_cedar = _load_cedar('defaults/file_safety.cedar')
_sentry_organization_default_cedar = _load_cedar('defaults/organization.cedar')


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

SENTRY_CATEGORIES: tuple[SentryCategoryInfo, ...] = (
    SentryCategoryInfo(
        id='pii',
        name='PII Detection',
        description='Detect and block personally identifiable information (PII) such as credit card numbers, SSNs, health data, and other sensitive personal data from being shared with AI chat services',
    ),
    SentryCategoryInfo(
        id='semantic',
        name='Semantic Threat Detection',
        description='Detect and block prompt injection, jailbreak attempts, and high-severity threats in messages, pasted content, and uploaded files',
    ),
    SentryCategoryInfo(
        id='content_safety',
        name='Content Safety',
        description='Detect and block violent, harmful, hateful, sexual, and profane content in AI interactions, including cut-and-paste safety rules',
    ),
    SentryCategoryInfo(
        id='file_safety',
        name='File & Attachment Safety',
        description='Enforce document sensitivity controls (MIP labels), block sensitive file uploads, detect secrets and PII in uploaded documents',
    ),
    SentryCategoryInfo(
        id='organization',
        name='Organization Rules',
        description='Organization-wide baselines, AI service allowlists, credential leakage prevention, and source code protection',
    ),
)


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

SENTRY_DEFAULTS: tuple[SentryDefaultPolicy, ...] = (
    SentryDefaultPolicy(
        id='sentry-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=_sentry_baseline_default_cedar,
        severity='low',
        tags=('baseline', 'permit-default', 'organization'),
        is_active=True,
    ),
    SentryDefaultPolicy(
        id='sentry-semantic-default',
        name='Semantic Threat Detection',
        description='Detect and block prompt injection, jailbreak attempts, and high-severity threats across messages, paste, and file uploads',
        category='semantic',
        cedar_text=_sentry_semantic_default_cedar,
        severity='critical',
        tags=('injection', 'jailbreak', 'owasp-llm01', 'owasp-llm02', 'baseline'),
        is_active=True,
    ),
    SentryDefaultPolicy(
        id='sentry-content-safety-default',
        name='Content Safety',
        description='Detect and block violent, harmful, hateful, sexual, and profane content including cut-and-paste safety enforcement',
        category='content_safety',
        cedar_text=_sentry_content_safety_default_cedar,
        severity='critical',
        tags=('violence', 'hate-speech', 'sexual', 'profanity', 'content-safety', 'paste-safety', 'baseline'),
        is_active=True,
    ),
)


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

SENTRY_TEMPLATES: tuple[SentryTemplate, ...] = (
    SentryTemplate(
        id='sentry-pii-default',
        name='PII Detection',
        description='Detect and block credit card numbers, SSNs, health data, and other PII in messages, pasted content, file uploads, and AI responses',
        category='pii',
        cedar_text=_sentry_pii_default_cedar,
        severity='critical',
        tags=('pii', 'privacy', 'compliance', 'pci-dss', 'gdpr', 'hipaa', 'baseline'),
    ),
    SentryTemplate(
        id='sentry-file-safety-default',
        name='File & Attachment Safety',
        description='Enforce MIP sensitivity labels, block confidential document uploads, detect secrets and PII in files, and restrict file types',
        category='file_safety',
        cedar_text=_sentry_file_safety_default_cedar,
        severity='critical',
        tags=('mip', 'document-sensitivity', 'file-upload', 'dlp', 'compliance'),
    ),
    SentryTemplate(
        id='sentry-organization-default',
        name='Organization Rules',
        description='Organization-wide policies: credential leakage prevention, source code protection, and secrets blocking across all interactions',
        category='organization',
        cedar_text=_sentry_organization_default_cedar,
        severity='critical',
        tags=('secrets', 'credentials', 'source-code', 'data-protection', 'organization'),
    ),
)


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

def get_sentry_defaults_by_category(category: str) -> list[SentryDefaultPolicy]:
    return [d for d in SENTRY_DEFAULTS if d.category == category]


def get_sentry_templates_by_category(category: str) -> list[SentryTemplate]:
    return [t for t in SENTRY_TEMPLATES if t.category == category]


def get_sentry_template_by_id(template_id: str) -> Optional[SentryTemplate]:
    return next((t for t in SENTRY_TEMPLATES if t.id == template_id), None)


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


__all__ = [
    # Types
    'SentryCategoryInfo',
    'SentryDefaultPolicy',
    'SentryTemplate',
    # Data
    'SENTRY_CATEGORIES',
    'SENTRY_DEFAULTS',
    'SENTRY_TEMPLATES',
    # Functions
    'get_sentry_defaults_by_category',
    'get_sentry_templates_by_category',
    'get_sentry_template_by_id',
    'get_sentry_templates_metadata_json',
]
