import { redirect } from 'next/navigation';
import { routes } from '@/lib/routing/RouteConfig';
import { DriverProfilePageQuery } from '@/lib/page-queries/DriverProfilePageQuery';
import { DriverProfilePageClient } from './DriverProfilePageClient';

export default async function DriverProfilePage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const result = await DriverProfilePageQuery.execute(id);

  if (result.isErr()) {
    const error = result.getError();
    if (error === 'NotFound') {
      redirect(routes.error.notFound);
    }
    return (
      <DriverProfilePageClient
        viewData={null}
        error={error}
      />
    );
  }

  const viewData = result.unwrap();
  return (
    <DriverProfilePageClient
      viewData={viewData}
    />
  );
}