class Pdf::Admissions::ApplicantAgreementService < 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_agreement_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_agreement.html.haml',
        locals: set_local_variables
      )
    end

    def set_local_variables
      {
        applicant: @applicant,
        agreements: agreements,
        responses: response_by_agreement
      }
    end

    def agreements
      @applicant.application.agreements
    end

    def response_by_agreement
      @applicant.applicant_agreements.pluck(:agreement_id, :response).to_h
    end
end
