"""GDPR audit log model.

⚠️ AUTO-GENERATED BY PRISM — DO NOT EDIT
This file is regenerated on every `prisme generate`.

Tracks all data access and modifications for GDPR compliance.
"""

from __future__ import annotations

from datetime import datetime

from sqlalchemy import DateTime, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from {{ package_name }}.models.base import Base


class PrivacyAuditLog(Base):
    """Audit trail for GDPR-relevant data operations.

    Records who accessed or modified personal data, when, and what changed.
    This model is append-only — records should never be updated or deleted.
    """

    __tablename__ = "privacy_audit_log"

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    timestamp: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, index=True
    )
    user_id: Mapped[str] = mapped_column(String(255), nullable=True, index=True)
    operation: Mapped[str] = mapped_column(
        String(50), nullable=False, index=True
    )  # read, create, update, delete, export, erase
    model_name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
    record_id: Mapped[str] = mapped_column(String(255), nullable=True)
    field_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
    ip_address: Mapped[str | None] = mapped_column(String(45), nullable=True)
    details: Mapped[str | None] = mapped_column(Text, nullable=True)
