class Admission::Applicants::AttachmentService < ApplicationService
  def initialize(application)
    @application = application
  end

  def props
    application_attachments.map do |application_attachment|
      attachment = application_attachment.attachment

      {
        id: attachment.id,
        name: attachment.name,
        description: attachment.description,
        filename: attachment.file.attachment&.filename,
        url: attachment.file.attachment&.service_url
      }
    end
  end

  def available?
    application_attachments.exists?
  end

  private
    def application_attachments
      @application_attachments ||= @application.application_attachments
        .includes(attachment: { file_attachment: :blob })
        .ordered
    end
end
