Rails.application.routes.draw do
  # For details on the DSL available within this file,
  # see http://guides.rubyonrails.org/routing.html

  root to: 'welcome#index'

  concern :paginatable do
    get '(page/:page)', action: :index, on: :collection, as: ''
  end

  concern :movies do
    resources :movies, only: [:index], concerns: :paginatable
  end

  resources :categories, only: [:index], concerns: :movies
  resources :genres, only: [:index], concerns: :movies

  resources :movies do
    resources :comments, only: [:create, :destroy]
  end

  resources :users, only: [:show, :create, :update, :edit]
  resources :sessions, only: [:create]

  get 'sign-in', to: 'sessions#new', as: :sign_in
  get 'sign-up', to: 'users#new', as: :sign_up
  delete 'sign-out', to: 'sessions#destroy', as: :sign_out

  get 'faq', to: 'pages#faq', as: :faq

  namespace :admin do
    resources :users, concerns: :paginatable
    resources :categories, concerns: :paginatable
    resources :genres, concerns: :paginatable
  end
end
