import { notFound, redirect } from 'next/navigation';
import { LeaderboardsPageQuery } from '@/lib/page-queries/page-queries/LeaderboardsPageQuery';
import { LeaderboardsPageWrapper } from './LeaderboardsPageWrapper';
import { routes } from '@/lib/routing/RouteConfig';

export default async function LeaderboardsPage() {
  const result = await LeaderboardsPageQuery.execute();
    
  if (result.isErr()) {
    const error = result.getError();
    
    // Handle different error types
    if (error === 'notFound') {
      notFound();
    } else if (error === 'redirect') {
      redirect(routes.public.home);
    } else {
      // serverError, networkError, unknown, validationError, unauthorized
      console.error('Leaderboards error:', error);
      notFound();
    }
  }
  
  // Success
  const viewData = result.unwrap();
  return <LeaderboardsPageWrapper data={viewData} />;
}