import { createBrowserRouter } from "react-router-dom";
import { AppLayout } from "@/components/AppLayout";
import { ProtectedRoute } from "@/components/ProtectedRoute";
import { LandingPage } from "@/pages/LandingPage";
import { LoginPage } from "@/pages/LoginPage";
import { OverviewPage } from "@/pages/OverviewPage";
import { PoliciesPage } from "@/pages/PoliciesPage";
import { UsersPage } from "@/pages/UsersPage";
import { ProvidersPage } from "@/pages/ProvidersPage";
import { AlertsPage } from "@/pages/AlertsPage";
import { LogsPage } from "@/pages/LogsPage";
import { PlaygroundPage } from "@/pages/PlaygroundPage";
import { SecurityPage } from "@/pages/SecurityPage";
import { CostsPage } from "@/pages/CostsPage";
import { CompliancePage } from "@/pages/CompliancePage";
import { NotFoundPage } from "@/pages/NotFoundPage";

// Documentation site
import { DocLayout } from "@/pages/docs/DocLayout";
import { DocsHomePage } from "@/pages/docs/DocsHomePage";
import { WhatIsVeylantPage } from "@/pages/docs/getting-started/WhatIsVeylantPage";
import { QuickStartPage } from "@/pages/docs/getting-started/QuickStartPage";
import { KeyConceptsPage } from "@/pages/docs/getting-started/KeyConceptsPage";
import { DockerComposePage } from "@/pages/docs/installation/DockerComposePage";
import { ConfigurationPage } from "@/pages/docs/installation/ConfigurationPage";
import { ProvidersPage as DocProvidersPage } from "@/pages/docs/installation/ProvidersPage";
import { AuthenticationPage } from "@/pages/docs/api-reference/AuthenticationPage";
import { ChatCompletionsPage } from "@/pages/docs/api-reference/ChatCompletionsPage";
import { PiiAnalysisPage } from "@/pages/docs/api-reference/PiiAnalysisPage";
import { AdminPoliciesPage } from "@/pages/docs/api-reference/AdminPoliciesPage";
import { AdminUsersPage } from "@/pages/docs/api-reference/AdminUsersPage";
import { AdminLogsPage } from "@/pages/docs/api-reference/AdminLogsPage";
import { AdminCompliancePage } from "@/pages/docs/api-reference/AdminCompliancePage";
import { AdminFlagsPage } from "@/pages/docs/api-reference/AdminFlagsPage";
import { PiiGuide } from "@/pages/docs/guides/PiiGuide";
import { RoutingGuide } from "@/pages/docs/guides/RoutingGuide";
import { RbacGuide } from "@/pages/docs/guides/RbacGuide";
import { ComplianceGuide } from "@/pages/docs/guides/ComplianceGuide";
import { MonitoringGuide } from "@/pages/docs/guides/MonitoringGuide";
import { CircuitBreakerGuide } from "@/pages/docs/guides/CircuitBreakerGuide";
import { DockerPage } from "@/pages/docs/deployment/DockerPage";
import { KubernetesPage } from "@/pages/docs/deployment/KubernetesPage";
import { BlueGreenPage } from "@/pages/docs/deployment/BlueGreenPage";
import { SecurityModelPage } from "@/pages/docs/security/SecurityModelPage";
import { ApiKeysPage } from "@/pages/docs/security/ApiKeysPage";
import { ChangelogPage } from "@/pages/docs/ChangelogPage";

export const router = createBrowserRouter([
  {
    path: "/",
    element: <LandingPage />,
  },
  {
    path: "/login",
    element: <LoginPage />,
  },
  {
    path: "/callback",
    // OIDC redirect handler — AuthProvider handles the callback automatically
    element: <LoginPage />,
  },
  {
    path: "/dashboard",
    element: (
      <ProtectedRoute>
        <AppLayout />
      </ProtectedRoute>
    ),
    children: [
      { index: true, element: <OverviewPage /> },
      { path: "playground", element: <PlaygroundPage /> },
      { path: "policies", element: <PoliciesPage /> },
      { path: "users", element: <UsersPage /> },
      { path: "providers", element: <ProvidersPage /> },
      { path: "security", element: <SecurityPage /> },
      { path: "costs", element: <CostsPage /> },
      { path: "alerts", element: <AlertsPage /> },
      { path: "logs", element: <LogsPage /> },
      { path: "compliance", element: <CompliancePage /> },
      { path: "*", element: <NotFoundPage /> },
    ],
  },
  // Documentation site — public, no auth required
  {
    path: "/docs",
    element: <DocLayout />,
    children: [
      { index: true, element: <DocsHomePage /> },
      // Getting Started
      { path: "getting-started/what-is-veylant", element: <WhatIsVeylantPage /> },
      { path: "getting-started/quick-start", element: <QuickStartPage /> },
      { path: "getting-started/concepts", element: <KeyConceptsPage /> },
      // Installation
      { path: "installation/docker", element: <DockerComposePage /> },
      { path: "installation/configuration", element: <ConfigurationPage /> },
      { path: "installation/providers", element: <DocProvidersPage /> },
      // API Reference
      { path: "api/authentication", element: <AuthenticationPage /> },
      { path: "api/chat-completions", element: <ChatCompletionsPage /> },
      { path: "api/pii", element: <PiiAnalysisPage /> },
      { path: "api/admin/policies", element: <AdminPoliciesPage /> },
      { path: "api/admin/users", element: <AdminUsersPage /> },
      { path: "api/admin/logs", element: <AdminLogsPage /> },
      { path: "api/admin/compliance", element: <AdminCompliancePage /> },
      { path: "api/admin/flags", element: <AdminFlagsPage /> },
      // Guides
      { path: "guides/pii", element: <PiiGuide /> },
      { path: "guides/routing", element: <RoutingGuide /> },
      { path: "guides/rbac", element: <RbacGuide /> },
      { path: "guides/compliance", element: <ComplianceGuide /> },
      { path: "guides/monitoring", element: <MonitoringGuide /> },
      { path: "guides/circuit-breaker", element: <CircuitBreakerGuide /> },
      // Deployment
      { path: "deployment/docker", element: <DockerPage /> },
      { path: "deployment/kubernetes", element: <KubernetesPage /> },
      { path: "deployment/blue-green", element: <BlueGreenPage /> },
      // Security
      { path: "security/model", element: <SecurityModelPage /> },
      { path: "security/api-keys", element: <ApiKeysPage /> },
      // Changelog
      { path: "changelog", element: <ChangelogPage /> },
    ],
  },
]);
