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: { id: string } }) {
  const result = await DriverProfilePageQuery.execute(params.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}
    />
  );
}