Rails.application.routes.draw do
  get "tags/index", to: "tags#index"
  get "tags/new", to: "tags#new"
  get "tags/create", to: "tags#create"
  get "tags/edit", to: "tags#edit"
  get "tags/update", to: "tags#update"
  get "tags/destroy", to: "tags#destroy"
  get "images/index", to: "images#index"
  get "images/show", to: "images#show"
  get "images/new", to: "images#new"
  get "images/create", to: "images#create"
  get "images/edit", to: "images#edit"
  get "images/update", to: "images#update"
  get "images/destroy", to: "images#destroy"
  get "images/search", to: "images#search"
  get "sessions/index", to: "sessions#index"
  get "sessions/show", to: "sessions#show"
  get "session/new", to: "sessions#new"
  get "sessions/security", to: "sessions#security"

  # Authentication routes
  resource :session
  resources :sessions, only: [ :index, :show ] do
    member do
      delete :destroy_session
    end
    collection do
      get :security
    patch :update_security
      post :terminate_all
    end
  end
  resources :passwords, param: :token
  resources :users, only: [ :new, :create ]

  # Image management routes
  resources :images do
    collection do
      get :search
    end
    member do
      patch :approve
      patch :reject
    end
  end

  # Tag management routes
  resources :tags, except: [ :show ]

  # Admin namespace for admin-only actions
  namespace :admin do
    get "users/index", to: "users#index"
    get "users/show", to: "users#show"
    get "users/edit", to: "users#edit"
    get "users/update", to: "users#update"
    get "users/destroy", to: "users#destroy"
    get "images/index", to: "images#index"
    get "images/show", to: "images#show"
    get "images/update", to: "images#update"
    get "images/destroy", to: "images#destroy"
    get "images/pending", to: "images#pending"
    get "images/approved", to: "images#approved"
    get "images/rejected", to: "images#rejected"
    get "images/approve", to: "images#approve"
    get "images/reject", to: "images#reject"
    get "images/add_tags", to: "images#add_tags"
    get "images/remove_tag", to: "images#remove_tag"
    get "dashboard/index", to: "dashboard#index"
    resources :images, only: [ :index, :show, :update, :destroy ] do
      member do
        patch :approve
        patch :reject
        post :add_tags
        delete :remove_tag
      end
      collection do
        get :pending
        get :approved
        get :rejected
      end
    end
    resources :users, only: [ :index, :show, :edit, :update, :destroy ]
    resources :tags, only: [ :index, :create, :destroy ]
    root to: "dashboard#index"
  end

  # Example route (can be removed later)
  get "inertia-example", to: "inertia_example#index"

  # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
  # Can be used by load balancers and uptime monitors to verify that the app is live.
  get "up" => "rails/health#show", as: :rails_health_check

  # Root path route
  root "images#index"
end