const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');

const userRoutes = require('./routes/userRoutes');
const investmentTypeRoutes = require('./routes/investmentTypeRoutes');
const investmentRentRoutes = require('./routes/investmentRentabilityRoutes');
const investmentRoutes = require('./routes/investmentRoutes');
const btcRoutes = require('./routes/btcRoutes');
const feeRoutes = require('./routes/feeRoutes');
const withdrawRoutes = require('./routes/withdrawRoutes');
const staffRoutes = require('./routes/staffRoutes');

const userModel = require('./models/userModel');
const investmentTypeModel = require('./models/investmentTypeModel');
const investmentRentModel = require('./models/investmentRentabilityModel');
const investmentModel = require('./models/investmentModel');

const app = express();

// ✅ CORS configurado corretamente para cookies
app.use(cors({
  origin: 'https://report.bcxcorretora.com.br:443',
  credentials: true
}));

app.use(express.json());
app.use(cookieParser());


// Registrar rotas
app.use('/auth', staffRoutes);
app.use('/api', userRoutes);
app.use('/api', investmentTypeRoutes);
app.use('/api', investmentRentRoutes);
app.use('/api', investmentRoutes);
app.use('/api', btcRoutes);
app.use('/api', feeRoutes);
app.use('/api', withdrawRoutes);

// Rota de teste
app.get('/', (req, res) => {
  res.send('API Running!');
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Servidor rodando na porta ${PORT}`);
});
