class Pdf::Admissions::ApplicantEssayService < Pdf::NewApplicationService
  def initialize(applicant)
    @applicant = applicant.decorate
  end

  private
    def header
      content = ActionController::Base.new.render_to_string(
        partial: 'pdf/headers/school_info.html.haml',
        locals: {
          school: @applicant.school,
          side_content_partial: 'pdf/admissions/applicant_essay_header.html.haml',
          side_content: {
            applicant: @applicant,
            school_year: @applicant.school_year,
            application: @applicant.application
          }
        }
      )
      { content: content, spacing: 25 }
    end

    def body
      ActionController::Base.new.render_to_string(
        partial: 'pdf/admissions/applicant_essay.html.haml',
        locals: set_local_variables
      )
    end

    def set_local_variables
      {
        applicant: @applicant,
        essays: essays,
        responses: response_by_essay
      }
    end

    def essays
      @applicant.application.essays
    end

    def response_by_essay
      @applicant.applicant_essays.index_by(&:essay_id)
    end
end
