Rails.application.routes.draw do
  devise_for :admins, skip: :registrations, controllers: {
      session: 'admins/sessions'
  }
  mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
  devise_for :organizations, controllers: {
      sessions: 'organizations/sessions',
      registrations: 'organizations/registrations'
  }
  devise_for :users, controllers: {
      sessions: 'users/sessions',
      registrations: 'users/registrations'
  }
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

  resources :applications # To be deleted, currently just for testing
  # resources :admins, only: [:show]
  resources :users, only: [:show]
  resources :organizations, only: [:show]

  resources :projects, only: [:index, :new, :show, :edit, :apply] do
    resources :applications, only: [:new, :show, :edit, :delete]
  end

  authenticated :user do
    root 'users#dashboard', as: :authenticated_user_root
    get '/my-projects', to: 'users#my_projects'
  end

  authenticated :organization do
    root 'organizations#dashboard', as: :authenticated_organization_root
    get '/my-projects', to: 'organizations#my_projects'
    resources :projects do
      resources :photos, only: [:new]
    end
  end

  namespace :api, defaults: { format: :json } do
    resources :organizations do
      resources :projects, only: [:index]
    end
    resources :projects, only: [:index, :create, :update, :destroy, :show]  do
      resources :applications, only: [:index, :decision]
    end
    resources :users
    resources :skills, only: [:create]
    resources :deliverable_types, only: [:create]

    resources :applications, only: [:create, :update, :destroy, :decide]
    resource :photos, only: [:create]
    post '/applications/:id/decide', to: 'applications#decide'
    post '/projects/filter', to: 'projects#filter'
    post '/applications/filter', to: 'applications#filter'
    get '/users/:user_id/applications', to: 'applications#user_index'
    get '/all_projects', to: 'projects#index_all'
    get '/projects/:project_id/photos', to: 'photos#index'
  end

  root 'pages#dashboard'

  get '*path' => redirect('/')
end
