class Admission::ApplicantDocument < ApplicationRecord
  include Admissions::ApplicantApplicationBroadcastable
  include Fileable

  belongs_to :applicant
  belongs_to :document

  delegate :school, to: :document
  delegate :application, to: :applicant
  delegate :school_year, to: :application

  has_one_attached :file

  validates :file, presence: true

  scope :by_profile, ->(flag) do
    return if flag.nil?

    includes(:document).where(admission_documents: { profile: flag })
  end
end
