Rails.application.routes.draw do
  resources :nico_tags, path: 'tags/nico', only: [:index, :update]

  scope 'tags/:parent_id/children', controller: :tag_children do
    post ':child_id', action: :create
    delete ':child_id', action: :destroy
  end

  resources :tags, only: [:index, :show, :update] do
    collection do
      get :autocomplete
      get 'name/:name', action: :show_by_name
    end
  end

  scope :preview, controller: :preview do
    get :title
    get :thumbnail
  end

  resources :wiki_pages, path: 'wiki', only: [:index, :show, :create, :update] do
    collection do
      get :search
      get :changes

      scope :title do
        get ':title/exists', action: :exists_by_title
        get ':title', action: :show_by_title
      end
    end

    member do
      get :exists
      get :diff
    end
  end

  resources :posts, only: [:index, :show, :create, :update] do
    collection do
      get :random
      get :changes
    end

    member do
      post :viewed
      delete :viewed, action: :unviewed
    end
  end

  resources :users, only: [:create, :update] do
    collection do
      post :verify
      get :me
      post 'code/renew', action: :renew
    end
  end
end
