import { NextRequest, NextResponse } from 'next/server'
import { settingsDB } from '@/lib/db'

// 获取系统设置
export async function GET() {
  try {
    const settings = await settingsDB.get()
    return NextResponse.json({ success: true, settings: settings?.data || null })
  } catch (error: any) {
    console.error('Get settings error:', error)
    return NextResponse.json({ 
      success: false, 
      error: error.message 
    }, { status: 500 })
  }
}

// 保存系统设置
export async function POST(req: NextRequest) {
  try {
    const body = await req.json()
    await settingsDB.update(body)
    return NextResponse.json({ success: true, message: '设置已保存' })
  } catch (error: any) {
    console.error('Save settings error:', error)
    return NextResponse.json({ 
      success: false, 
      error: error.message 
    }, { status: 500 })
  }
}
