const express = require('express')
const cors = require('cors')
const errorHandler = require('./src/middleware/ErrorHandler.js')
const app = express()
const path = require('path');
// const hospitalRoutes = require('./src/routes/HospitalRoute.js')
const provinceRoutes = require('./src/routes/admin/ProvinceRoute.js')
const authRoutes = require('./src/routes/auth/AuthRoute.js')
// const userRoutes = require('./src/routes/UserRoute.js')
const cityRoutes = require('./src/routes/admin/CityRoute.js')
const salesRoutes = require('./src/routes/admin/SalesRoute.js')
const adminRoutes = require('./src/routes/superadmin/AdminRoute.js')
const hospitalRoutes = require('./src/routes/admin/HospitalRoute.js')
const salesHospitalRoutes = require('./src/routes/sales/HospitalRoute.js')
const vendorRoutes = require('./src/routes/admin/VendorRoute.js')
const logRoutes = require('./src/routes/superadmin/LogRoute.js')
const areaRoutes = require('./src/routes/sales/AreaRoute.js')
const vendorSalesRoutes = require('./src/routes/sales/VendorRoute.js')
const { port } = require('./config/config.js')

app.use(cors())
app.use(express.json())
app.use('/storage/', express.static(path.join(__dirname, 'storage/')));

const apiV1 = express.Router();

// apiV1.use('/hospitals', hospitalRoutes);
apiV1.use('/province', provinceRoutes);
apiV1.use('/auth', authRoutes);
// apiV1.use('/user', userRoutes);
apiV1.use('/city', cityRoutes);
apiV1.use('/sales', salesRoutes);
apiV1.use('/admin', adminRoutes);
apiV1.use('/hospital', hospitalRoutes);
apiV1.use('/hospital-area', salesHospitalRoutes);
apiV1.use('/vendor', vendorRoutes);
apiV1.use('/logs', logRoutes);
apiV1.use('/area', areaRoutes);
apiV1.use('/vendor-sales', vendorSalesRoutes);

app.get('/', (req, res) => {
    res.send('Selamat Datang di API Radar Farmagitechs');
});

app.use('/v1/api', apiV1);
app.use(errorHandler);

app.listen(port, () => {
    console.log(`Server started on port ${port}`);
})