// IRU Qualification API Routes
// Routes for qualification engine

import { Router } from 'express';
import { qualificationEngine } from '@/core/iru/qualification/qualification-engine.service';
import { workflowEngine } from '@/core/iru/workflow/workflow-engine.service';
import { zeroTrustAuthMiddleware } from '@/integration/api-gateway/middleware/auth.middleware';
import { adminPermissionMiddleware } from '@/integration/api-gateway/middleware/admin-permission.middleware';

const router = Router();

// All qualification routes require admin authentication
router.use(zeroTrustAuthMiddleware);
router.use(adminPermissionMiddleware);

/**
 * @route POST /api/v1/iru/qualification/process
 * @desc Process qualification assessment
 * @access Admin
 */
router.post('/process', async (req, res, next) => {
  try {
    const result = await qualificationEngine.processQualification(req.body);
    res.json({
      success: true,
      data: result,
      timestamp: new Date(),
    });
  } catch (error) {
    return next(error);
  }
});

/**
 * @route POST /api/v1/iru/qualification/workflow/transition
 * @desc Transition workflow state
 * @access Admin
 */
router.post('/workflow/transition', async (req, res, next) => {
  try {
    const { inquiryId, fromState, toState, metadata } = req.body;
    const state = await workflowEngine.transitionQualification(inquiryId, fromState, toState, metadata);
    res.json({
      success: true,
      data: state,
      timestamp: new Date(),
    });
  } catch (error) {
    return next(error);
  }
});

export default router;
