Rails.application.routes.draw do

  resources :notes
  resources :recipes do
    collection do
      post :preview_steps
    end
    resources :logs, only: [:new, :create]
  end

  resources :logs, except: [:new, :create]

  resources :foods, except: [] do
    collection do
      get :usda_food_search

      constraints format: 'json' do
        get :prefetch
        get :convert
      end
    end
  end

  match '/foods(/:id)/select_ndbn' => 'foods#select_ndbn', via: [:post, :patch, :put]

  resources :tags, only: [:index] do
    collection do
      constraints format: 'json' do
        get :search
        get :prefetch
      end
    end
  end

  resources :task_lists, only: [:index, :show, :create, :update, :destroy] do
    member do
      patch 'add_recipe/:recipe_id', action: :add_recipe
    end
    resources :task_items, only: [:create, :update] do
      collection do
        delete '/', action: :destroy, as: :destroy
        patch 'complete', action: :complete
      end
    end
  end

  resource :user, only: [:new, :create, :edit, :update]

  get '/login' => 'users#login', as: :login
  post '/login' => 'users#verify_login'
  get '/logout' => 'users#logout', as: :logout
  get '/user' => 'users#show', as: :show

  get '/about' => 'home#about', as: :about

  scope '/calculator', controller: :calculator, as: :calculator do
    get '/' => :index
    get '/calculate' => :calculate
    get '/ingredient_search' => :ingredient_search
  end

  scope '/ingredients', controller: :ingredients, as: :ingredients do
    get '/search' => :search
  end

  namespace 'admin' do
    resources :users, except: [:new, :create]
  end

  get 'sw.js' => 'home#sw'
  root 'home#index'


end
