Rails.application.routes.draw do
  # Routes for the onboarding process
  get "onboarding", to: "onboarding#index", as: "onboarding"
  post "onboarding", to: "onboarding#create"

  devise_for :users
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  resources :categories

  # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
  # Can be used by load balancers and uptime monitors to verify that the app is live.
  get "up" => "rails/health#show", as: :rails_health_check

  # Defines the root path route ("/")
  root "home#index"

  resources :discussions do
    member do
      patch :reopen
      patch :close
      post "favorite", to: "favorite_discussions#create"
      delete "unfavorite", to: "favorite_discussions#destroy"
    end
    resources :replies, only: [ :create, :edit, :update, :destroy ] do
      member do
        patch :toggle_answer
      end
    end
    # Nested route for toggling reactions on a discussion
    resources :reactions, only: [] do
      collection do
        post :toggle
      end
    end
    resources :votes, only: [ :create, :destroy ]
  end

  patch "discussions/:id/toggle_pin", to: "discussions#toggle_pin", as: "toggle_pin_discussion"

  # Admin routes (protected by authentication and admin check)
  namespace :admin do
    resource :system_configuration, only: [ :show, :edit, :update ]
  end

  # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
  # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
  # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker

  # Defines the route for PWA service worker.
  # ... existing code ...
end
