// server/routes/sitemap.xml.ts
// 동적 sitemap 생성

export default defineEventHandler(async (event) => {
  const siteUrl = 'https://fincure.officialsite.kr'

  // 정적 페이지 목록
  const staticPages = [
    { loc: '/', priority: 1.0, changefreq: 'daily' },
    { loc: '/about', priority: 0.8, changefreq: 'monthly' },
    { loc: '/pricing', priority: 0.9, changefreq: 'weekly' },
    { loc: '/features', priority: 0.8, changefreq: 'monthly' },
    { loc: '/guide', priority: 0.7, changefreq: 'weekly' },
    { loc: '/help', priority: 0.7, changefreq: 'weekly' },
    { loc: '/legal-info', priority: 0.6, changefreq: 'monthly' },
    { loc: '/contact', priority: 0.6, changefreq: 'monthly' },
    { loc: '/qna', priority: 0.6, changefreq: 'weekly' },
    { loc: '/blog', priority: 0.7, changefreq: 'daily' },
    { loc: '/auth/login', priority: 0.5, changefreq: 'monthly' },
    { loc: '/auth/register', priority: 0.5, changefreq: 'monthly' },
  ]

  // 로그인 필요 페이지 (우선순위 낮게)
  const protectedPages = [
    { loc: '/dashboard', priority: 0.5, changefreq: 'daily' },
    { loc: '/document-writer', priority: 0.8, changefreq: 'weekly' },
    { loc: '/my-documents', priority: 0.7, changefreq: 'daily' },
    { loc: '/my-cases', priority: 0.7, changefreq: 'daily' },
    { loc: '/payment', priority: 0.6, changefreq: 'monthly' },
  ]

  const allPages = [...staticPages, ...protectedPages]

  // XML 생성
  const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${allPages.map(page => `  <url>
    <loc>${siteUrl}${page.loc}</loc>
    <changefreq>${page.changefreq}</changefreq>
    <priority>${page.priority}</priority>
    <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
  </url>`).join('\n')}
</urlset>`

  setHeader(event, 'Content-Type', 'application/xml')
  return sitemap
})
