class Admin::Legacy::Discipline::Students::DetentionsController <
  Admin::Legacy::Discipline::Controller
  def index
    render_success :ok, json: detentions.order(:posted_on).map { |l| detention_props(l) }
  end

  def show
    render_success :ok, json: detention_props(detention)
  end

  private
    def detentions
      student.discipline_detentions
    end

    def detention
      @detention ||= detentions.find_by(id: params[:id])
    end

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

    def detention_props(detention)
      {
        id: detention.id,
        author_id: detention.author_id,
        author_name: detention.author&.full_name(:reverse),
        monitor_id: detention.monitor_id,
        monitor_name: detention.monitor&.full_name(:reverse),
        length: detention.length,
        completed: detention.completed,
        comments: detention.comments,
        served_on: detention.served_on,
        posted_on: detention.posted_on
      }
    end
end
