import { Router } from 'express';
import {
  assetFolders,
  assetLinks,
  assets,
  createAssetAction,
  createAssetFolderAction,
  createAssetLinkAction,
  deleteAssetAction,
  deleteAssetFolderAction,
  deleteAssetLinkAction,
  downloadAssetAction,
  getAssetAction,
  updateAssetAction,
  updateAssetFolderAction,
  viewAssetAction
} from '../controllers/assetController.js';
import { requireAuth } from '../middleware/auth.js';
import { assetUpload } from '../middleware/upload.js';

export const assetRoutes = Router();

// Asset routes stay API-first: UI upload, package builders, and external clients share this surface.
assetRoutes.get('/folders', requireAuth, assetFolders);
assetRoutes.post('/folders', requireAuth, createAssetFolderAction);
assetRoutes.put('/folders/:id', requireAuth, updateAssetFolderAction);
assetRoutes.delete('/folders/:id', requireAuth, deleteAssetFolderAction);

assetRoutes.delete('/links/:linkId', requireAuth, deleteAssetLinkAction);
assetRoutes.get('/', requireAuth, assets);
assetRoutes.post('/', requireAuth, assetUpload.single('file'), createAssetAction);
assetRoutes.get('/:id/download', requireAuth, downloadAssetAction);
assetRoutes.get('/:id/view', requireAuth, viewAssetAction);
assetRoutes.get('/:id/links', requireAuth, assetLinks);
assetRoutes.post('/:id/links', requireAuth, createAssetLinkAction);
assetRoutes.get('/:id', requireAuth, getAssetAction);
assetRoutes.put('/:id', requireAuth, updateAssetAction);
assetRoutes.delete('/:id', requireAuth, deleteAssetAction);
