class StopWordsController < ApplicationController
  before_action :set_stop_word, only: %i[ show edit update destroy ]

  # GET /stop_words or /stop_words.json
  def index
    @stop_words = StopWord.all
  end

  # GET /stop_words/1 or /stop_words/1.json
  def show
  end

  # GET /stop_words/new
  def new
    @stop_word = StopWord.new
  end

  # GET /stop_words/1/edit
  def edit
  end

  # POST /stop_words or /stop_words.json
  def create
    @stop_word = StopWord.new(stop_word_params)

    respond_to do |format|
      if @stop_word.save
        format.html { redirect_to stop_words_url, notice: "Stop word was successfully created." }
        format.json { render :show, status: :created, location: @stop_word }
      else
        format.html { render :new, status: :unprocessable_entity }
        format.json { render json: @stop_word.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /stop_words/1 or /stop_words/1.json
  def update
    respond_to do |format|
      if @stop_word.update(stop_word_params)
        format.html { redirect_to stop_words_url, notice: "Stop word was successfully updated." }
        format.json { render :show, status: :ok, location: @stop_word }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @stop_word.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /stop_words/1 or /stop_words/1.json
  def destroy
    @stop_word.destroy

    respond_to do |format|
      format.html { redirect_to stop_words_url, notice: "Stop word was successfully destroyed." }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_stop_word
      @stop_word = StopWord.find(params[:id])
    end

    # Only allow a list of trusted parameters through.
    def stop_word_params
      params.require(:stop_word).permit(:word)
    end
end
