import { Router } from 'express';
import {
  cloneScriptAction,
  createFolderAction,
  createScriptAction,
  deleteFolderAction,
  deleteScriptAction,
  folders,
  getScriptAction,
  scriptUsageAction,
  scripts,
  scriptVersions,
  testRunScriptAction,
  updateFolderAction,
  updateScriptAction
} from '../controllers/libraryController.js';
import { requireAuth } from '../middleware/auth.js';

export const folderRoutes = Router();
export const scriptRoutes = Router();

// Folders and scripts are split for clean URLs while sharing library visibility rules.
folderRoutes.get('/', requireAuth, folders);
folderRoutes.post('/', requireAuth, createFolderAction);
folderRoutes.put('/:id', requireAuth, updateFolderAction);
folderRoutes.delete('/:id', requireAuth, deleteFolderAction);

scriptRoutes.get('/', requireAuth, scripts);
scriptRoutes.post('/', requireAuth, createScriptAction);
scriptRoutes.get('/:id/usage', requireAuth, scriptUsageAction);
scriptRoutes.post('/:id/clone', requireAuth, cloneScriptAction);
scriptRoutes.post('/:id/test-run', requireAuth, testRunScriptAction);
scriptRoutes.get('/:id', requireAuth, getScriptAction);
scriptRoutes.put('/:id', requireAuth, updateScriptAction);
scriptRoutes.delete('/:id', requireAuth, deleteScriptAction);
scriptRoutes.get('/:id/versions', requireAuth, scriptVersions);
