"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkflowController = void 0;
const openapi = require("@nestjs/swagger");
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const decorators_1 = require("../decorators");
const workflow_dto_1 = require("../dtos/workflow.dto");
const enum_1 = require("../enum");
const auth_guard_1 = require("../middleware/auth.guard");
const workflow_service_1 = require("../services/workflow.service");
const validation_1 = require("../validation");
let WorkflowController = class WorkflowController {
    service;
    constructor(service) {
        this.service = service;
    }
    createWorkflow(auth, dto) {
        return this.service.create(auth, dto);
    }
    searchWorkflows(auth, dto) {
        return this.service.search(auth, dto);
    }
    getWorkflowTriggers() {
        return this.service.getTriggers();
    }
    getWorkflow(auth, { id }) {
        return this.service.get(auth, id);
    }
    getWorkflowForShare(auth, { id }) {
        return this.service.share(auth, id);
    }
    updateWorkflow(auth, { id }, dto) {
        return this.service.update(auth, id, dto);
    }
    updateWorkflowV3(auth, { id }, dto) {
        return this.service.update(auth, id, dto);
    }
    deleteWorkflow(auth, { id }) {
        return this.service.delete(auth, id);
    }
};
exports.WorkflowController = WorkflowController;
__decorate([
    (0, common_1.Post)(),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowCreate }),
    (0, decorators_1.Endpoint)({
        summary: 'Create a workflow',
        description: 'Create a new workflow, the workflow can also be created with empty filters and actions.',
        history: decorators_1.HistoryBuilder.v3(),
    }),
    openapi.ApiResponse({ status: 201, type: require("../dtos/workflow.dto").WorkflowResponseDto }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, workflow_dto_1.WorkflowCreateDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "createWorkflow", null);
__decorate([
    (0, common_1.Get)(),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowRead }),
    (0, decorators_1.Endpoint)({
        summary: 'List all workflows',
        description: 'Retrieve a list of workflows available to the authenticated user.',
        history: decorators_1.HistoryBuilder.v3(),
    }),
    openapi.ApiResponse({ status: 200, type: [require("../dtos/workflow.dto").WorkflowResponseDto] }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, workflow_dto_1.WorkflowSearchDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "searchWorkflows", null);
__decorate([
    (0, common_1.Get)('triggers'),
    (0, auth_guard_1.Authenticated)({ permission: false }),
    (0, decorators_1.Endpoint)({
        summary: 'List all workflow triggers',
        description: 'Retrieve a list of all available workflow triggers.',
        history: decorators_1.HistoryBuilder.v3(),
    }),
    openapi.ApiResponse({ status: 200, type: [require("../dtos/workflow.dto").WorkflowTriggerResponseDto] }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Array)
], WorkflowController.prototype, "getWorkflowTriggers", null);
__decorate([
    (0, common_1.Get)(':id'),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowRead }),
    (0, decorators_1.Endpoint)({
        summary: 'Retrieve a workflow',
        description: 'Retrieve information about a specific workflow by its ID.',
        history: decorators_1.HistoryBuilder.v3(),
    }),
    openapi.ApiResponse({ status: 200, type: require("../dtos/workflow.dto").WorkflowResponseDto }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Param)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, validation_1.UUIDParamDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "getWorkflow", null);
__decorate([
    (0, common_1.Get)(':id/share'),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowRead }),
    (0, decorators_1.Endpoint)({
        summary: 'Retrieve a workflow',
        description: 'Retrieve a workflow details without ids, default values, etc.',
        history: decorators_1.HistoryBuilder.v3(),
    }),
    openapi.ApiResponse({ status: 200, type: require("../dtos/workflow.dto").WorkflowShareResponseDto }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Param)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, validation_1.UUIDParamDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "getWorkflowForShare", null);
__decorate([
    (0, common_1.Put)(':id'),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowUpdate }),
    (0, decorators_1.Endpoint)({
        summary: 'Update a workflow',
        description: 'Update the information of a specific workflow by its ID. This endpoint can be used to update the workflow name, description, trigger type, filters and actions order, etc.',
        history: new decorators_1.HistoryBuilder().added('v3.0.0').deprecated('v3', { replacementId: 'updateWorkflow' }),
    }),
    openapi.ApiResponse({ status: 200, type: require("../dtos/workflow.dto").WorkflowResponseDto }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Param)()),
    __param(2, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, validation_1.UUIDParamDto,
        workflow_dto_1.WorkflowUpdateDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "updateWorkflow", null);
__decorate([
    (0, common_1.Patch)(':id'),
    (0, swagger_1.ApiExcludeEndpoint)(),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowUpdate }),
    openapi.ApiResponse({ status: 200, type: require("../dtos/workflow.dto").WorkflowResponseDto }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Param)()),
    __param(2, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, validation_1.UUIDParamDto,
        workflow_dto_1.WorkflowUpdateDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "updateWorkflowV3", null);
__decorate([
    (0, common_1.Delete)(':id'),
    (0, auth_guard_1.Authenticated)({ permission: enum_1.Permission.WorkflowDelete }),
    (0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
    (0, decorators_1.Endpoint)({
        summary: 'Delete a workflow',
        description: 'Delete a workflow by its ID.',
        history: decorators_1.HistoryBuilder.v3(),
    }),
    openapi.ApiResponse({ status: common_1.HttpStatus.NO_CONTENT }),
    __param(0, (0, auth_guard_1.Auth)()),
    __param(1, (0, common_1.Param)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, validation_1.UUIDParamDto]),
    __metadata("design:returntype", Promise)
], WorkflowController.prototype, "deleteWorkflow", null);
exports.WorkflowController = WorkflowController = __decorate([
    (0, swagger_1.ApiTags)('Workflows'),
    (0, common_1.Controller)('workflows'),
    __metadata("design:paramtypes", [workflow_service_1.WorkflowService])
], WorkflowController);
//# sourceMappingURL=workflow.controller.js.map