class Admin::Legacy::ClassroomsController < Admin::Controller
  def index
    render_success :ok, json: classrooms.map { |c| classroom_props(c) }
  end

  private
    def classrooms
      current_school.classrooms
        .by_type(params[:type])
        .by_department(params[:department_ids])
        .by_semesters(current_school, params[:semesters])
        .where.not(type: :sports_team)
        .not_attached_to_a_course(params[:no_course_attached])
        .ordered
    end

    def classroom_props(classroom)
      {
        id: classroom.id,
        name: classroom.name,
        section: classroom.section,
        primary_teacher: classroom.primary_teacher&.full_name(:reverse),
        type: classroom.type,
        department_id: classroom.department_id? ? classroom.department_id : nil
      }
    end
end
