const express = require('express');
const app = express();
const cors = require('cors');
require("dotenv").config();

const corsOptions = {
  origin: process.env.URL_CORS, // sin slash al final
  methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
  allowedHeaders: ["Content-Type", "Authorization"]
};
app.use(cors(corsOptions));

app.use(express.json());

//rutas
const authRoutes = require('./routes/auth.routes');
const employeeRoutes = require('./routes/employee.routes');
const contractsRoutes = require('./routes/contract.routes');
const reportcontractRoutes = require('./routes/reportcontract.routes');
const productRoutes = require('./routes/product.routes');
const expenseRoutes = require('./routes/expense.routes');
const statusRoutes = require('./routes/status.routes');
const paymentRoutes = require('./routes/payment.routes');
const settingsRoutes = require('./routes/settings.routes');
const emailRoutes = require('./routes/mail.routes');
const incomeRoutes = require('./routes/incomes.routes');
const purchaseRoutes = require('./routes/purchase.routes');
const exchangeRoutes = require('./routes/exchange.routes');
const hotelRoutes = require('./routes/hotelpl.routes');
const restaurantRoutes = require('./routes/restaurantpl.routes');
const incomehrxRoutes = require('./routes/incomehrx.routes');

//Prefijo
app.use('/api/employees', employeeRoutes);
app.use('/api/contracts', contractsRoutes);
app.use('/api/reportcontracts', reportcontractRoutes);
app.use('/api/products', productRoutes);
app.use('/api/auth', authRoutes);
app.use('/api/expenses', expenseRoutes);
app.use('/api/status', statusRoutes);
app.use('/api/payment', paymentRoutes);
app.use('/api/settings',settingsRoutes);
app.use('/api/emails',emailRoutes);
app.use('/api/incomes',incomeRoutes);
app.use('/api/incomeshrx',incomehrxRoutes);
app.use('/api/purchases',purchaseRoutes);
app.use('/api/exchange',exchangeRoutes);
app.use('/api/hotelpl',hotelRoutes);
app.use('/api/restaurantpl',restaurantRoutes);

module.exports = app;
