"""
Notification Events — Constants
Ported & adapted từ BrightBean Studio apps/notifications/models.py
"""

class EventType:
    # Social feedback events
    NEW_SOCIAL_MESSAGE     = "new_social_message"
    NEGATIVE_SPIKE         = "negative_spike"          # Negative rate vượt ngưỡng
    SOCIAL_SENTIMENT_REPORT= "social_sentiment_report" # Báo cáo hàng tuần

    # AI Content pipeline
    CONTENT_SUBMITTED      = "content_submitted"       # AI tạo content chờ review
    CONTENT_APPROVED       = "content_approved"        # Marketing đã approve
    CONTENT_REJECTED       = "content_rejected"        # Marketing reject
    CONTENT_CHANGES        = "content_changes_requested"
    CONTENT_PUBLISHED      = "content_published"       # Đã publish lên social
    CONTENT_FAILED         = "content_failed"          # Publish thất bại

    # Learning loop events
    AI_RULES_UPDATED       = "ai_rules_updated"        # Feedback loop cập nhật rules
    FEEDBACK_MILESTONE     = "feedback_milestone"      # Đạt N feedbacks

    # System
    PUBLISH_RETRY          = "publish_retry"           # Đang retry publish
    API_TOKEN_EXPIRED      = "api_token_expired"       # Token FB/IG hết hạn

    ALL = [
        NEW_SOCIAL_MESSAGE, NEGATIVE_SPIKE, SOCIAL_SENTIMENT_REPORT,
        CONTENT_SUBMITTED, CONTENT_APPROVED, CONTENT_REJECTED,
        CONTENT_CHANGES, CONTENT_PUBLISHED, CONTENT_FAILED,
        AI_RULES_UPDATED, FEEDBACK_MILESTONE,
        PUBLISH_RETRY, API_TOKEN_EXPIRED,
    ]


class Channel:
    IN_APP  = "in_app"
    EMAIL   = "email"
    WEBHOOK = "webhook"


# Default channels per event type
DEFAULT_CHANNELS: dict[str, dict[str, bool]] = {
    EventType.NEW_SOCIAL_MESSAGE:      {Channel.IN_APP: True,  Channel.EMAIL: False, Channel.WEBHOOK: False},
    EventType.NEGATIVE_SPIKE:          {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: True},
    EventType.SOCIAL_SENTIMENT_REPORT: {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: False},
    EventType.CONTENT_SUBMITTED:       {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: False},
    EventType.CONTENT_APPROVED:        {Channel.IN_APP: True,  Channel.EMAIL: False, Channel.WEBHOOK: False},
    EventType.CONTENT_REJECTED:        {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: False},
    EventType.CONTENT_CHANGES:         {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: False},
    EventType.CONTENT_PUBLISHED:       {Channel.IN_APP: True,  Channel.EMAIL: False, Channel.WEBHOOK: True},
    EventType.CONTENT_FAILED:          {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: True},
    EventType.AI_RULES_UPDATED:        {Channel.IN_APP: True,  Channel.EMAIL: False, Channel.WEBHOOK: False},
    EventType.FEEDBACK_MILESTONE:      {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: False},
    EventType.PUBLISH_RETRY:           {Channel.IN_APP: True,  Channel.EMAIL: False, Channel.WEBHOOK: False},
    EventType.API_TOKEN_EXPIRED:       {Channel.IN_APP: True,  Channel.EMAIL: True,  Channel.WEBHOOK: False},
}

# Non-critical: suppress khi quiet hours
NON_CRITICAL = {
    EventType.NEW_SOCIAL_MESSAGE,
    EventType.AI_RULES_UPDATED,
    EventType.CONTENT_PUBLISHED,
    EventType.SOCIAL_SENTIMENT_REPORT,
}
