class ApplicationRecord < ActiveRecord::Base
  include NumberDisplayHelper

  attr_accessor :_extra_data

  self.abstract_class = true

  def format_time(time)
    time.present? ? time.strftime('%Y-%m-%d %H:%M') : ''
  end

  def display_extra_data(key)
    _extra_data&.[](key)
  end

  def allow_sync_to_trustie?
    Rails.env.production? && EduSetting.get('host_name') == 'https://www.educoder.net'
  end

  def test_check_power
    User.current.id == self.hack.user_id || User.current.is_certification_teacher || User.current.is_shixun_marker ||
        User.current.admin_or_business?
  end

  def verify_sensitive_content(field, field_name)
    if field.present?
      workds = HarmoniousDictionary.harmonious_words(field)
      raise("#{field_name}包含#{ workds.join('、') }等敏感词汇，请重新输入") if workds.present?
    end
  end

end
