defmodule CentralcloudStaff.Router do
  use Phoenix.Router
  import Phoenix.LiveView.Router

  @session_opts [store: :cookie, key: "_centralcloud_staff_session", signing_salt: "ops_salt_2026"]
  def session_opts, do: @session_opts

  pipeline :api do
    plug :accepts, ["json"]
  end

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, html: {CentralcloudStaff.Layouts, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :auth do
    plug CentralcloudStaff.Plugs.RequireStaff
  end

  scope "/api", CentralcloudStaff do
    pipe_through :api
    get "/health", HealthController, :check
    post "/mcp/wazuh", WazuhMcpController, :call
  end

  scope "/", CentralcloudStaff do
    pipe_through :browser

    get "/login", SessionController, :new
    delete "/logout", SessionController, :delete
  end

  scope "/", CentralcloudStaff do
    pipe_through [:browser, :auth]

    live "/", DashboardLive, :index
    live "/oncall", OnCallLive, :index
    live "/incidents", IncidentsLive, :index
    live "/incidents/:id", IncidentLive, :show
    live "/stakeholders", StakeholdersLive, :index
    live "/chat", ChatLive, :index
  end
end
