class Pdf::Nursing::LogsService < Pdf::NewApplicationService
  include DateRangeHelper

  def initialize(school, params)
    @school = school
    @dates = params['dates']
  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/logs_header',
          side_content: formated_dates
        }
      )
      { content: content, spacing: 25 }
    end

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

    def set_local_variables
      { logs: logs }
    end

    def logs
      @school.nursing_logs
        .includes(:complaint, :author, :student)
        .with_date_range(datetime_range(@dates))
        .map(&:decorate)
    end

    def formated_dates
      dates = @dates.split(',')
      { start: dates.first.to_date, end: dates.last.to_date }
    end
end
