class EnemiesController < ApplicationController
  before_action :set_enemy
  def update
    if @enemy.update(enemy_params)
      render json: {data:@enemy},status: :ok
    else  
      render json: {errors:@enemy.errors},status: :unprocessable_entity
    end
  end

  def destroy
    if @enemy.destroy
      render json: @enemy,status: :no_content
    else
      render json: {errors:@enemy.errors},status: :ok
    end
  end

  private 
  def enemy_params
    params.permit(:name,:power_base,:power_step,:level,:kind)
  end
  #Verifica se existe um Enemy com o id passado
  def set_enemy
    @enemy = Enemy.find(params[:id])
  rescue ActiveRecord::RecordNotFound => e
    render json: {message:e.message},status: :not_found
  end
end
