class Support::Training::NotificationsController < Support::ApplicationController
  def index
    render_success :ok, json: notifications
  end

  def show
    render_success :ok, json: notification
  end

  def create
    notification = notifications.build(notification_params)
    if notification.save
      render_success :ok, json: notification
    else
      render_error :unprocessable_entity, errors: notification
    end
  end

  def update
    if notification.update(notification_params)
      render_success :ok, json: notification
    else
      render_error :unprocessable_entity, errors: notification
    end
  end

  def destroy
    if notification.destroy
      render_success :ok
    else
      render_error :unprocessable_entity, errors: notification
    end
  end

  private
    def notifications
      Help::Notification.all
    end

    def notification
      @notification ||= notifications.find_by(id: params[:id])
    end

    def notification_params
      params.permit(:name, :body, :link, :route_name, :expiration, :active)
    end

    def area
      'communication'
    end
end
