class Deerjikist < ApplicationRecord
  self.primary_key = :platform, :code

  belongs_to :tag

  validates :platform, presence: true
  validates :code, presence: true
  validates :tag_id, presence: true

  validate :tag_must_be_deerjikist

  enum :platform, nico: 'nico', youtube: 'youtube'

  private

  def tag_must_be_deerjikist
    if tag && !(tag.deerjikist?)
      errors.add :tag, 'タグはニジラー・カテゴリである必要があります．'
    end
  end
end
