import express from 'express';
import { getSettings, updateSettings, uploadLogo, serveLogo } from '../controllers/systemSettingsController.js';
import { requireDeveloper } from '../middleware/authMiddleware.js';
import { uploadLogoDetails } from '../middleware/uploadMiddleware.js';

const router = express.Router();

// Public/Auth access to read settings
router.get('/', getSettings);

// Protected update
router.put('/', requireDeveloper, updateSettings);

// Protected upload
router.post('/logo', requireDeveloper, uploadLogoDetails.single('logo'), uploadLogo);

// Public access to view logo (noauth needed for login screen etc)
router.get('/logo-image/:filename', (req, res) => {
    // Use static import to ensure bundler compatibility
    serveLogo(req, res);
});

// Global Admin Routes
import { getGlobalUsers, getGlobalOrganizations, toggleOrganizationBan } from '../controllers/systemSettingsController.js';

router.get('/users', requireDeveloper, getGlobalUsers);
router.get('/organizations', requireDeveloper, getGlobalOrganizations);
router.post('/organizations/ban', requireDeveloper, toggleOrganizationBan);

export default router;
