class Admin::Legacy::Nursing::Students::MedicalsController < Admin::Legacy::Nursing::Controller
  def show
    render_success :ok, json: medical_props
  end

  def update
    if student_medical.update(medical_params)
      render_success :ok, medical_props
    else
      render_error :unprocessable_entity, errors: student_medical
    end
  end

  private
    def student
      @student ||= current_school.students.find_by(id: params[:student_id])
    end

    def student_medical
      @student_medical ||= student.find_or_build_student_medical
    end

    def medical_params
      params.permit(
        :asthma,
        :diabetes,
        :seizures,
        :deafness,
        :add,
        :bladder,
        :hemophiliac,
        :sicklecell,
        :sight_impairment,
        :healthy,
        :allergies,
        :comments,
        :alerts,
        :tylenol,
        :ibuprofen,
        :medication,
        :exempt
      )
    end

    def medical_props
      {
        asthma: student_medical.asthma?,
        diabetes: student_medical.diabetes?,
        seizures: student_medical.seizures?,
        deafness: student_medical.deafness?,
        add: student_medical.add?,
        bladder: student_medical.bladder?,
        hemophiliac: student_medical.hemophiliac?,
        sicklecell: student_medical.sicklecell?,
        sight_impairment: student_medical.sight_impairment?,
        healthy: student_medical.healthy?,
        allergies: student_medical.allergies,
        comments: student_medical.comments,
        alerts: student_medical.alerts,
        tylenol: student_medical.tylenol?,
        ibuprofen: student_medical.ibuprofen?,
        medication: student_medical.medication,
        exempt: student_medical.exempt
      }
    end
end
