class ProviderGroupsController < ApplicationController
  before_action :set_provider_group, only: %i[ show edit update destroy ]

  # GET /provider_groups or /provider_groups.json
  def index
    @provider_groups = ProviderGroup.all
  end

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

  # GET /provider_groups/new
  def new
    @provider_group = ProviderGroup.new
  end

  # GET /provider_groups/1/edit
  def edit
  end

  # POST /provider_groups or /provider_groups.json
  def create
    @provider_group = ProviderGroup.new(provider_group_params)

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

  # PATCH/PUT /provider_groups/1 or /provider_groups/1.json
  def update
    respond_to do |format|
      if @provider_group.update(provider_group_params)
        format.html { redirect_to @provider_group, notice: "Provider group was successfully updated.", status: :see_other }
        format.json { render :show, status: :ok, location: @provider_group }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @provider_group.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /provider_groups/1 or /provider_groups/1.json
  def destroy
    @provider_group.destroy!

    respond_to do |format|
      format.html { redirect_to provider_groups_path, notice: "Provider group was successfully destroyed.", status: :see_other }
      format.json { head :no_content }
    end
  end

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

    # Only allow a list of trusted parameters through.
    def provider_group_params
      params.require(:provider_group).permit(:name)
    end
end
