from datetime import datetime
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, JSON, Text
from sqlalchemy.orm import relationship
from app.core.database import Base


class MaskingRule(Base):
    __tablename__ = "masking_rule"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), nullable=False)
    level_id = Column(Integer, ForeignKey("data_level.id"), nullable=True)
    category_id = Column(Integer, ForeignKey("category.id"), nullable=True)
    algorithm = Column(String(20), nullable=False)  # mask, truncate, hash, generalize, replace
    params = Column(JSON, default=dict)  # algorithm-specific params
    is_active = Column(Boolean, default=True)
    description = Column(Text)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    level = relationship("DataLevel")
    category = relationship("Category")
