Rails.application.routes.draw do
  namespace :community do
    resource :session, only: %i[create destroy]
    resource :patient, only: %i[new create edit update]

    resources :appointments, only: %i[index create destroy] do
      collection do
        get :home
        get :vaccinated # not a collection one but due to the way we have appointments right now
      end
    end
  end

  devise_for :users, controllers: { sessions: 'users/sessions' }
  devise_scope :user do
    namespace :operator do
      resources :ubs, only: %i[index] do
        resources :appointments, only: %i[index show]
      end
    end

    namespace :admin do
      resources :appointments, only: %i[index show new create] do
        member do
          patch :check_in
          patch :undo_check_in

          patch :check_out
          patch :undo_check_out

          patch :suspend
          patch :activate

          patch :remove_patient
        end
      end
      resources :appointments_bulks, only: %i[new create]
      resources :groups
      resources :neighborhoods
      resources :pages
      resources :patients, only: %i[index new create edit update show] do
        member do
          patch :unblock
        end
      end
      resources :conditions
      resources :inquiry_questions do
        resources :inquiry_answers
      end
      resources :ubs
      resources :users
      resources :vaccines
    end
    resources :appointments, only: %i[index]
  end

  resources :pages, only: :show, path: '/p'

  get 'community', to: redirect('/community/appointments/home')
  get 'operator', to: redirect('/operator/ubs')
  get 'admin', to: redirect('/admin/patients')
  root 'home#index'
end
