import type { MetadataRoute } from 'next';
import { SITE_URL } from '@/config';

/**
 * Every top-level route segment that sits behind the auth middleware, for every actor (customer/
 * nurse/admin/partner). Kept in sync by hand with `src/constants/routes.ts` — there is no single
 * "private roots" export there (only a `PUBLIC_PATHS` allow-list), and deriving one automatically
 * would need to walk every `ROUTES.*` entry down to its first segment, which is more machinery
 * than this short, reviewable list (ui-phase-13).
 */
const PRIVATE_ROOT_SEGMENTS = [
  'select-role',
  'onboarding',
  'search',
  'bookings',
  'patients',
  'addresses',
  'wallet',
  'profile',
  'support',
  'notifications',
  'nurse',
  'admin',
  'partner',
];

/**
 * Replaces the starter `public/robots.txt` (two contradictory `User-agent: *` blocks) with a real
 * policy: allow the public marketing/auth surface, disallow every private root for every locale.
 * @route /robots.txt
 */
export default function robots(): MetadataRoute.Robots {
  return {
    rules: {
      userAgent: '*',
      allow: '/',
      disallow: PRIVATE_ROOT_SEGMENTS.map((segment) => `/*/${segment}`),
    },
    sitemap: `${SITE_URL}/sitemap.xml`,
  };
}
