import { NextResponse } from 'next/server'

export const dynamic = "force-static"

// 获取新闻列表（静态数据）
export async function GET(request: Request) {
  const { searchParams } = new URL(request.url)
  const page = parseInt(searchParams.get('page') || '1')
  const limit = parseInt(searchParams.get('limit') || '10')
  const category = searchParams.get('category')

  // 静态数据示例
  const allNews = [
    {
      id: 1,
      title: "白马家园荣获数字经济创新大奖",
      category: "公司新闻",
      excerpt: "白马家园在数字经济领域取得突破性进展，荣获行业创新大奖。",
      createdAt: new Date().toISOString(),
      source: '手动发布'
    },
    {
      id: 2,
      title: "AI数字人技术引领新零售变革",
      category: "行业洞察",
      excerpt: "白马家园推出的AI数字人解决方案正在重塑新零售体验。",
      createdAt: new Date(Date.now() - 86400000).toISOString(),
      source: '白马精选'
    },
    {
      id: 3,
      title: "收单外包服务机构备案正式获批",
      category: "公司新闻",
      excerpt: "白马家园成功获得收单外包服务机构备案，合规能力再上新台阶。",
      createdAt: new Date(Date.now() - 172800000).toISOString(),
      source: '手动发布'
    }
  ]

  // 分类筛选
  const filteredNews = category 
    ? allNews.filter(item => item.category === category)
    : allNews

  // 分页
  const total = filteredNews.length
  const paginatedNews = filteredNews.slice((page - 1) * limit, page * limit)

  return NextResponse.json({
    news: paginatedNews,
    pagination: {
      page,
      limit,
      total,
      totalPages: Math.ceil(total / limit),
    },
  })
}

// 创建新闻（禁用）
export async function POST(request: Request) {
  return NextResponse.json(
    { error: '新闻发布功能已禁用，请通过后台手动更新' },
    { status: 403 }
  )
}
