import express from "express";
import cors from "cors";
import usersRouter from './routes/users.js';
import foodRecordsRouter from './routes/food-records.js';
import weightRecordsRouter from './routes/weight-records.js';
import aiChatRouter from './routes/ai-chat.js';

const app = express();
const port = process.env.PORT || 9091;

// Middleware
app.use(cors());
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb', extended: true }));

// Health check
app.get('/api/v1/health', (req, res) => {
  res.status(200).json({ status: 'ok' });
});

// API Routes
// 注意：静态路由必须在动态路由之前
app.use('/api/v1/users', usersRouter);
app.use('/api/v1/food-records', foodRecordsRouter);
app.use('/api/v1/weight-records', weightRecordsRouter);
app.use('/api/v1/ai-chat', aiChatRouter);


app.listen(port, () => {
  console.log(`Server listening at http://localhost:${port}/`);
});
