class SupportedLanguage < ApplicationRecord
  has_many :suggested_meanings,
           foreign_key: :language_code,
           primary_key: :code,
           dependent: :restrict_with_exception

  validates :code, presence: true, uniqueness: true
  validates :name, presence: true
  validates :native_name, presence: true

  def self.valid_codes
    Rails.cache.fetch("supported_languages_codes", expires_in: 1.hour) do
      pluck(:code).map(&:to_s)
    end
  end
end
