import { notFound, redirect } from 'next/navigation';
import { DashboardPageQuery } from '@/lib/page-queries/DashboardPageQuery';
import { DashboardPageClient } from '@/client-wrapper/DashboardPageClient';
import { logger } from '@/lib/infrastructure/logging/logger';

export default async function DashboardPage() {
  const result = await DashboardPageQuery.execute();
    
  if (result.isErr()) {
    const error = result.getError();
    
    // Handle different error types
    if (error === 'notFound') {
      notFound();
    } else if (error === 'redirect') {
      redirect('/');
    } else {
      // serverError, networkError, unknown, validationError, unauthorized
      logger.error('Dashboard error', undefined, { errorType: error });
      notFound();
    }
  }
  
  // Success
  const viewData = result.unwrap();
  return <DashboardPageClient viewData={viewData} />;
}
