"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const api = __importStar(require("../../api/yaml-workflows"));
const router = (0, express_1.Router)();
/**
 * POST /api/yaml-workflows/:id/deploy
 * Deploy all YAML workflows sharing this workflow's app_id as a merged version.
 * Bumps the version and deploys all graphs together.
 */
router.post('/:id/deploy', async (req, res) => {
    const result = await api.deployYamlWorkflow({ id: req.params.id });
    res.status(result.status).json(result.data ?? { error: result.error });
});
/**
 * POST /api/yaml-workflows/:id/activate
 * Activate the deployed version for this workflow's app_id and register all workers.
 */
router.post('/:id/activate', async (req, res) => {
    const result = await api.activateYamlWorkflow({ id: req.params.id });
    res.status(result.status).json(result.data ?? { error: result.error });
});
/**
 * POST /api/yaml-workflows/:id/invoke
 * Invoke an active YAML workflow with parameters.
 * Body: { data, sync?: boolean }
 */
router.post('/:id/invoke', async (req, res) => {
    const result = await api.invokeYamlWorkflow({
        id: req.params.id,
        data: req.body.data,
        sync: req.body.sync,
        timeout: req.body.timeout,
        execute_as: req.body.execute_as,
    }, req.auth?.userId ? { userId: req.auth.userId } : undefined);
    res.status(result.status).json(result.data ?? { error: result.error });
});
/**
 * POST /api/yaml-workflows/:id/archive
 * Archive a YAML workflow (stops accepting new invocations).
 */
router.post('/:id/archive', async (req, res) => {
    const result = await api.archiveYamlWorkflow({ id: req.params.id });
    res.status(result.status).json(result.data ?? { error: result.error });
});
/**
 * POST /api/yaml-workflows/:id/restore
 * Restore an archived YAML workflow back to draft status for redeployment.
 */
router.post('/:id/restore', async (req, res) => {
    const result = await api.restoreYamlWorkflow({ id: req.params.id });
    res.status(result.status).json(result.data ?? { error: result.error });
});
exports.default = router;
