import { createBrowserRouter } from "react-router-dom";
import AppLayout from "../components/layout/AppLayout";
import ApiKeyCreatePage from "../features/api-keys/ApiKeyCreatePage";
import ApiKeyListPage from "../features/api-keys/ApiKeyListPage";
import AuditLogsPage from "../features/audit/AuditLogsPage";
import AuthPage from "../features/auth/AuthPage";
import DashboardPage from "../features/dashboard/DashboardPage";
import GlobalOverviewPage from "../features/overview/GlobalOverviewPage";
import LoginPage from "../features/auth/LoginPage";
import AuthCallbackPage from "../features/auth/AuthCallbackPage";
import TenantGroupCreatePage from "../features/tenant-groups/routes/TenantGroupCreatePage";
import TenantGroupDetailPage from "../features/tenant-groups/routes/TenantGroupDetailPage";
import TenantGroupListPage from "../features/tenant-groups/routes/TenantGroupListPage";
import TenantGroupProfileTab from "../features/tenant-groups/routes/TenantGroupProfileTab";
import TenantGroupTenantsTab from "../features/tenant-groups/routes/TenantGroupTenantsTab";
import TenantGroupAdminsTab from "../features/tenant-groups/routes/TenantGroupAdminsTab";
import TenantCreatePage from "../features/tenants/routes/TenantCreatePage";
import TenantDetailPage from "../features/tenants/routes/TenantDetailPage";
import TenantListPage from "../features/tenants/routes/TenantListPage";
import { TenantProfilePage } from "../features/tenants/routes/TenantProfilePage";
import { TenantSchemaPage } from "../features/tenants/routes/TenantSchemaPage";
import TenantAdminsTab from "../features/tenants/routes/TenantAdminsTab";
import UserCreatePage from "../features/users/UserCreatePage";
import UserDetailPage from "../features/users/UserDetailPage";
import UserListPage from "../features/users/UserListPage";

export const router = createBrowserRouter(
  [
    {
      path: "/login",
      element: <LoginPage />,
    },
    {
      path: "/auth/callback",
      element: <AuthCallbackPage />,
    },
    {
      path: "/",
      element: <AppLayout />,
      children: [
        { index: true, element: <GlobalOverviewPage /> },
        { path: "dashboard", element: <DashboardPage /> },
        { path: "audit-logs", element: <AuditLogsPage /> },
        { path: "auth", element: <AuthPage /> },
        { path: "users", element: <UserListPage /> },
        { path: "users/new", element: <UserCreatePage /> },
        { path: "users/:id", element: <UserDetailPage /> },
        { path: "tenants", element: <TenantListPage /> },
        { path: "tenants/new", element: <TenantCreatePage /> },
        { path: "tenant-groups", element: <TenantGroupListPage /> },
        { path: "tenant-groups/new", element: <TenantGroupCreatePage /> },
        {
          path: "tenant-groups/:id",
          element: <TenantGroupDetailPage />,
          children: [
            { index: true, element: <TenantGroupProfileTab /> },
            { path: "tenants", element: <TenantGroupTenantsTab /> },
            { path: "admins", element: <TenantGroupAdminsTab /> },
          ],
        },
        {
          path: "tenants/:tenantId",
          element: <TenantDetailPage />,
          children: [
            { index: true, element: <TenantProfilePage /> },
            { path: "admins", element: <TenantAdminsTab /> },
            { path: "schema", element: <TenantSchemaPage /> },
          ],
        },
        { path: "api-keys", element: <ApiKeyListPage /> },
        { path: "api-keys/new", element: <ApiKeyCreatePage /> },
      ],
    },
  ],
  // React Router v7 플래그 사전 적용 (현재 타입 정의에 없어 any 캐스팅)
  {
    future: {
      v7_startTransition: true,
    },
  } as unknown as Parameters<typeof createBrowserRouter>[1],
);
