import express from 'express';
import helmet from 'helmet';
import cors from 'cors';
import morgan from 'morgan';
import dotenv from 'dotenv';
dotenv.config();

import authRoutes from './routes/auth.js';
import tournamentsRoutes from './routes/tournaments.js';
import matchesRoutes from './routes/matches.js';

const app = express();
app.use(helmet());
app.use(cors());
app.use(express.json());
app.use(morgan('dev'));

app.get('/api/health', (req,res)=> res.json({ ok:true }));

app.use('/api/auth', authRoutes);
app.use('/api/tournaments', tournamentsRoutes);
app.use('/api/matches', matchesRoutes);

const port = process.env.PORT || 4000;
app.listen(port, ()=>{
  console.log(`SuperSunday backend listening on :${port}`);
});
