import 'package:go_router/go_router.dart';
import '../../features/shell/app_shell.dart';
import '../../features/home/home_page.dart';
import '../../features/messages/message_list_page.dart';
import '../../features/profile/profile_page.dart';
import '../../features/expense/expense_list_page.dart';
import '../../features/expense/expense_apply_page.dart';
import '../../features/expense/expense_detail_page.dart';
import '../../features/overtime/overtime_list_page.dart';
import '../../features/overtime/overtime_apply_page.dart';
import '../../features/overtime/overtime_detail_page.dart';
import '../../features/vehicle/vehicle_list_page.dart';
import '../../features/vehicle/vehicle_apply_page.dart';
import '../../features/vehicle/vehicle_detail_page.dart';
import '../../features/outing_log/outing_log_list_page.dart';
import '../../features/outing_log/outing_log_create_page.dart';
import '../../features/outing_log/outing_log_detail_page.dart';
import '../../features/announcement/announcement_list_page.dart';
import '../../features/announcement/announcement_detail_page.dart';
import '../../features/announcement/announcement_create_page.dart';
import '../../features/expense_application/expense_application_list_page.dart';
import '../../features/expense_application/expense_application_detail_page.dart';
import '../../features/expense_application/expense_application_apply_page.dart';
import '../../features/report/expense_detail_report_page.dart';
import '../../features/report/overtime_detail_report_page.dart';
import '../../features/report/vehicle_detail_report_page.dart';
import '../../features/report/expense_apply_detail_report_page.dart';
import '../../features/report/outing_log_report_page.dart';
import '../../features/admin/admin_permissions_page.dart';

GoRouter createAppRouter() {
  return GoRouter(
    initialLocation: '/',
    routes: [
      StatefulShellRoute.indexedStack(
        builder: (_, __, navigationShell) => AppShell(child: navigationShell),
        branches: [
          StatefulShellBranch(
            routes: [
              GoRoute(
                path: '/messages',
                builder: (_, __) => const MessageListPage(),
              ),
            ],
          ),
          StatefulShellBranch(
            routes: [
              GoRoute(
                path: '/',
                builder: (_, __) => const HomePage(),
              ),
              GoRoute(
                path: '/expense/list',
                builder: (_, __) => const ExpenseListPage(),
              ),
              GoRoute(
                path: '/expense/apply',
                builder: (_, state) =>
                    ExpenseApplyPage(editId: state.uri.queryParameters['id']),
              ),
              GoRoute(
                path: '/expense/detail/:id',
                builder: (_, state) =>
                    ExpenseDetailPage(id: state.pathParameters['id']!),
              ),
              GoRoute(
                path: '/overtime/list',
                builder: (_, __) => const OvertimeListPage(),
              ),
              GoRoute(
                path: '/overtime/apply',
                builder: (_, state) =>
                    OvertimeApplyPage(editId: state.uri.queryParameters['id']),
              ),
              GoRoute(
                path: '/overtime/detail/:id',
                builder: (_, state) =>
                    OvertimeDetailPage(id: state.pathParameters['id']!),
              ),
              GoRoute(
                path: '/vehicle/list',
                builder: (_, __) => const VehicleListPage(),
              ),
              GoRoute(
                path: '/vehicle/apply',
                builder: (_, state) =>
                    VehicleApplyPage(editId: state.uri.queryParameters['id']),
              ),
              GoRoute(
                path: '/vehicle/detail/:id',
                builder: (_, state) =>
                    VehicleDetailPage(id: state.pathParameters['id']!),
              ),
              GoRoute(
                path: '/outing-log/list',
                builder: (_, __) => const OutingLogListPage(),
              ),
              GoRoute(
                path: '/outing-log/create',
                builder: (_, __) => const OutingLogCreatePage(),
              ),
              GoRoute(
                path: '/outing-log/detail/:id',
                builder: (_, state) =>
                    OutingLogDetailPage(id: state.pathParameters['id']!),
              ),
              GoRoute(
                path: '/announcement/list',
                builder: (_, __) => const AnnouncementListPage(),
              ),
              GoRoute(
                path: '/announcement/detail/:id',
                builder: (_, state) =>
                    AnnouncementDetailPage(id: state.pathParameters['id']!),
              ),
              GoRoute(
                path: '/announcement/create',
                builder: (_, __) => const AnnouncementCreatePage(),
              ),
              GoRoute(
                path: '/expense-apply/list',
                builder: (_, __) => const ExpenseApplicationListPage(),
              ),
              GoRoute(
                path: '/expense-apply/detail/:id',
                builder: (_, state) => ExpenseApplicationDetailPage(
                    id: state.pathParameters['id']!),
              ),
              GoRoute(
                path: '/expense-apply/apply',
                builder: (_, state) => ExpenseApplicationApplyPage(
                    id: state.uri.queryParameters['id']),
              ),
              GoRoute(
                path: '/report/expense-detail',
                builder: (_, __) => const ExpenseDetailReportPage(),
              ),
              GoRoute(
                path: '/report/expense-apply-detail',
                builder: (_, __) => const ExpenseApplyDetailReportPage(),
              ),
              GoRoute(
                path: '/report/overtime-detail',
                builder: (_, __) => const OvertimeDetailReportPage(),
              ),
              GoRoute(
                path: '/report/vehicle-detail',
                builder: (_, __) => const VehicleDetailReportPage(),
              ),
              GoRoute(
                path: '/report/outing-log',
                builder: (_, __) => const OutingLogReportPage(),
              ),
              GoRoute(
                path: '/admin/permissions',
                builder: (_, __) => const AdminPermissionsPage(),
              ),
            ],
          ),
          StatefulShellBranch(
            routes: [
              GoRoute(
                path: '/profile',
                builder: (_, __) => const ProfilePage(),
              ),
            ],
          ),
        ],
      ),
    ],
  );
}
