class Pdf::Nursing::ImmunizationsService < Pdf::NewApplicationService
  def initialize(student)
    @student = student.decorate
    @school = student.school
  end

  private
    def header
      content = ActionController::Base.new.render_to_string(
        partial: 'pdf/headers/school_info.html.haml',
        locals: {
          school: @school,
          side_content_partial: 'pdf/nursing/immunization_header.html.haml',
          side_content: { date: Time.zone.today }
        }
      )
      { content: content, spacing: 25 }
    end

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

    def set_local_variables
      {
        student: @student,
        student_vaccines: student_vaccines,
        vaccines: vaccines,
        grade_labels: @school.grades_hash
      }
    end

    def student_vaccines
      @student_vaccines ||= @student.nursing_vaccine_records.index_by(&:vaccine_id)
    end

    def vaccines
      @school.nursing_vaccine_configs
        .includes(:vaccine)
        .order('StudentVaccines.Vaccine ASC')
        .decorate
    end
end
