
import { MetadataRoute } from 'next'
import { VERTICALS } from '@/config/verticals'
import { getApiUrl } from '@/lib/api-config'

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
    const baseUrl = 'https://fediversion.runfoo.run'

    // Static routes
    const routes = [
        '',
        '/shows',
        '/songs',
        '/venues',
        '/login',
        '/register',
        '/about',
        '/terms',
        '/privacy',
    ].map((route) => ({
        url: `${baseUrl}${route}`,
        lastModified: new Date(),
        changeFrequency: 'daily' as const,
        priority: 1,
    }))

    // Generate routes for each vertical
    const verticalRoutes = VERTICALS.flatMap((vertical) => [
        {
            url: `${baseUrl}/${vertical.slug}`,
            lastModified: new Date(),
            changeFrequency: 'daily' as const,
            priority: 0.9,
        },
        {
            url: `${baseUrl}/${vertical.slug}/songs`,
            lastModified: new Date(),
            changeFrequency: 'weekly' as const,
            priority: 0.8,
        },
        {
            url: `${baseUrl}/${vertical.slug}/shows`,
            lastModified: new Date(),
            changeFrequency: 'weekly' as const,
            priority: 0.8,
        },
    ])

    // TODO: Fetch dynamic routes (shows, songs) from API once we have a performant way to get all slugs
    // For now, we rely on the main list pages being indexed and crawlers following links

    return [...routes, ...verticalRoutes]
}
