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


class ComplianceRule(Base):
    __tablename__ = "compliance_rule"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(200), nullable=False)
    standard = Column(String(50), nullable=False)  # dengbao, pipl, gdpr
    description = Column(Text)
    check_logic = Column(String(50), nullable=False)  # check_masking, check_encryption, check_audit, check_level
    severity = Column(String(20), default="medium")  # low, medium, high, critical
    is_active = Column(Boolean, default=True)
    created_at = Column(DateTime, default=datetime.utcnow)


class ComplianceIssue(Base):
    __tablename__ = "compliance_issue"

    id = Column(Integer, primary_key=True, index=True)
    rule_id = Column(Integer, nullable=False)
    project_id = Column(Integer, nullable=True)
    entity_type = Column(String(20), nullable=False)  # project, source, column
    entity_id = Column(Integer, nullable=False)
    entity_name = Column(String(200))
    severity = Column(String(20), default="medium")
    description = Column(Text)
    suggestion = Column(Text)
    status = Column(String(20), default="open")  # open, resolved, ignored
    resolved_at = Column(DateTime, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow)
