import express from 'express';

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

// 中间件
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// 健康检查接口
app.get('/api/health', (req, res) => {
  res.json({ status: 'ok', message: 'Backend service is running' });
});

// 模拟登录接口
app.post('/api/auth/login', (req, res) => {
  const { username, password } = req.body;
  res.json({
    success: true,
    data: {
      token: 'mock-token-123',
      refreshToken: 'mock-refresh-token-123',
      user: {
        id: '1',
        username: username || 'admin',
        role: 'ADMIN',
        tenantId: 'default-tenant',
        shopId: 'default-shop'
      }
    }
  });
});

// 启动服务器
app.listen(PORT, () => {
  console.log(`简化后端服务运行在 http://localhost:${PORT}`);
});

export default app;
