import { MetadataRoute } from 'next';

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://yourdomain.com';

  // 静态页面
  const staticPages: MetadataRoute.Sitemap = [
    {
      url: baseUrl,
      lastModified: new Date(),
      changeFrequency: 'daily',
      priority: 1,
    },
    {
      url: `${baseUrl}/character`,
      lastModified: new Date(),
      changeFrequency: 'daily',
      priority: 0.8,
    },
    {
      url: `${baseUrl}/novel`,
      lastModified: new Date(),
      changeFrequency: 'daily',
      priority: 0.8,
    },
    {
      url: `${baseUrl}/video`,
      lastModified: new Date(),
      changeFrequency: 'daily',
      priority: 0.8,
    },
    {
      url: `${baseUrl}/record`,
      lastModified: new Date(),
      changeFrequency: 'daily',
      priority: 0.7,
    },
  ];

  // TODO: 如果需要动态生成角色详情页的 sitemap，可以在这里调用 API
  // 例如：
  // try {
  //   const characters = await fetchAllCharacters(); // 需要实现这个函数
  //   const characterPages: MetadataRoute.Sitemap = characters.map((char) => ({
  //     url: `${baseUrl}/character/${char.id}`,
  //     lastModified: new Date(char.updatedAt),
  //     changeFrequency: 'weekly',
  //     priority: 0.9,
  //   }));
  //   return [...staticPages, ...characterPages];
  // } catch (error) {
  //   console.error('Failed to generate sitemap:', error);
  //   return staticPages;
  // }

  return staticPages;
}

