class Comment < ApplicationRecord
  belongs_to :user
  belongs_to :commentable, polymorphic: true
  belongs_to :language,
             class_name: "SupportedLanguage",
             foreign_key: :language_code,
             primary_key: :code,
             optional: true

  validates :body, presence: true

  after_create_commit :notify_users

  private

  def notify_users
    return if language_code.blank?

    # Placeholder for notification logic once we decide delivery channels.
    users_to_notify = User.where(primary_language: language_code).where.not(id: user_id)
    # puts "Notifying users: #{users_to_notify.pluck(:email).join(", ")}"
  end
end
