package services import ( "context" "strings" "gorm.io/gorm" ) // moderationKeywordRow maps to moderation_keywords table for Pluck. type moderationKeywordRow struct { Word string `gorm:"column:word"` } // CommentModerationService provides deterministic keyword-based moderation (no ML). // v0.10.3 F201: ORIGIN_REVISION_SUMMARY §2 "Modération : règles déterministes" type CommentModerationService struct { db *gorm.DB } // NewCommentModerationService creates a new comment moderation service. func NewCommentModerationService(db *gorm.DB) *CommentModerationService { return &CommentModerationService{db: db} } // ContainsBannedKeyword checks if content contains any banned keyword (case-insensitive). // Returns true if content should be rejected. func (s *CommentModerationService) ContainsBannedKeyword(ctx context.Context, content string) (bool, error) { var rows []moderationKeywordRow if err := s.db.WithContext(ctx). Table("moderation_keywords"). Select("word"). Find(&rows).Error; err != nil { return false, err } contentLower := strings.ToLower(content) for _, row := range rows { if strings.Contains(contentLower, strings.ToLower(row.Word)) { return true, nil } } return false, nil }