"""
CustomReport ORM model.

Represents extracted custom report data from bug reports with severity "custom".
Each report contains structured key/value pairs (e.g., accuracy scores, guardrails flags)
extracted from bugs.raw_data → report.content.data.

The schema is customer-agnostic — report fields vary per feature's
custom_report_configurations.
"""

import sqlalchemy as sa
from sqlmodel import Field, SQLModel


class CustomReport(SQLModel, table=True):
    """
    Custom report data extracted from bug raw_data.

    Stores flattened key/value pairs from report.content.data as a JSON dict.
    Large text fields (e.g., plain_text_interactions) are excluded by default
    to keep this table lean (~1-2KB per row vs 30KB raw_data blobs).

    Attributes:
        bug_id: Primary key + FK to bugs.id (1:1 relationship)
        configuration_id: Links to feature's custom_report_configurations[].id
        report_data: Flat JSON dict of key/value pairs from the report
    """

    __tablename__ = "custom_reports"

    bug_id: int = Field(primary_key=True, foreign_key="bugs.id")
    configuration_id: int | None = Field(default=None, index=True)
    report_data: str = Field(sa_column=sa.Column(sa.Text(), nullable=False))
