"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapMethod = exports.mapTemplate = exports.PluginTemplateResponseDto = exports.PluginMethodResponseDto = exports.PluginMethodSearchDto = exports.PluginResponseDto = exports.PluginSearchDto = void 0;
exports.mapPlugin = mapPlugin;
const openapi = require("@nestjs/swagger");
const nestjs_zod_1 = require("nestjs-zod");
const enum_1 = require("../enum");
const workflow_1 = require("../utils/workflow");
const zod_1 = __importDefault(require("zod"));
const PluginSearchSchema = zod_1.default
    .object({
    id: zod_1.default.uuidv4().optional().describe('Plugin ID'),
    enabled: zod_1.default.boolean().optional().describe('Whether the plugin is enabled'),
    name: zod_1.default.string().optional(),
    version: zod_1.default.string().optional(),
    title: zod_1.default.string().optional(),
    description: zod_1.default.string().optional(),
})
    .meta({ id: 'PluginSearchDto' });
const PluginMethodResponseSchema = zod_1.default
    .object({
    key: zod_1.default.string().describe('Key'),
    name: zod_1.default.string().describe('Name'),
    title: zod_1.default.string().describe('Title'),
    description: zod_1.default.string().describe('Description'),
    types: zod_1.default.array(enum_1.WorkflowTypeSchema).describe('Workflow types'),
    uiHints: zod_1.default.array(zod_1.default.string()).describe('Ui hints'),
    schema: zod_1.default.object().optional(),
    hostFunctions: zod_1.default.boolean(),
})
    .meta({ id: 'PluginMethodResponseDto' });
const PluginResponseSchema = zod_1.default
    .object({
    id: zod_1.default.uuidv4().describe('Plugin ID'),
    name: zod_1.default.string().describe('Plugin name'),
    title: zod_1.default.string().describe('Plugin title'),
    description: zod_1.default.string().describe('Plugin description'),
    author: zod_1.default.string().describe('Plugin author'),
    version: zod_1.default.string().describe('Plugin version'),
    createdAt: zod_1.default.string().describe('Creation date'),
    updatedAt: zod_1.default.string().describe('Last update date'),
    methods: zod_1.default.array(PluginMethodResponseSchema).describe('Plugin methods'),
})
    .meta({ id: 'PluginResponseDto' });
const PluginTemplateStepResponseSchema = zod_1.default
    .object({
    method: zod_1.default.string().describe('Step plugin method'),
    config: zod_1.default.record(zod_1.default.string(), zod_1.default.unknown()).nullable().describe('Step configuration'),
    enabled: zod_1.default.boolean().optional().describe('Whether the step is enabled'),
})
    .meta({ id: 'PluginTemplateStepResponseDto' });
const PluginTemplateResponseSchema = zod_1.default
    .object({
    key: zod_1.default.string().describe('Template key (unique across all templates)'),
    title: zod_1.default.string().describe('Template title'),
    description: zod_1.default.string().describe('Template description'),
    trigger: enum_1.WorkflowTriggerSchema.describe('Workflow trigger'),
    steps: zod_1.default.array(PluginTemplateStepResponseSchema).describe('Workflow steps'),
    uiHints: zod_1.default.array(zod_1.default.string()).describe('Ui hints, for example "smart-album"'),
})
    .meta({ id: 'PluginTemplateResponseDto' });
const PluginMethodSearchSchema = zod_1.default
    .object({
    id: zod_1.default.uuidv4().optional().describe('Plugin method ID'),
    enabled: zod_1.default.boolean().optional().describe('Whether the plugin method is enabled'),
    name: zod_1.default.string().optional(),
    title: zod_1.default.string().optional(),
    description: zod_1.default.string().optional(),
    type: enum_1.WorkflowTypeSchema.optional().describe('Workflow types'),
    trigger: enum_1.WorkflowTriggerSchema.optional().describe('Workflow trigger'),
    pluginName: zod_1.default.string().optional().describe('Plugin name'),
    pluginVersion: zod_1.default.string().optional().describe('Plugin version'),
})
    .meta({ id: 'PluginMethodSearchDto' });
class PluginSearchDto extends (0, nestjs_zod_1.createZodDto)(PluginSearchSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PluginSearchDto = PluginSearchDto;
class PluginResponseDto extends (0, nestjs_zod_1.createZodDto)(PluginResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PluginResponseDto = PluginResponseDto;
class PluginMethodSearchDto extends (0, nestjs_zod_1.createZodDto)(PluginMethodSearchSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PluginMethodSearchDto = PluginMethodSearchDto;
class PluginMethodResponseDto extends (0, nestjs_zod_1.createZodDto)(PluginMethodResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PluginMethodResponseDto = PluginMethodResponseDto;
class PluginTemplateResponseDto extends (0, nestjs_zod_1.createZodDto)(PluginTemplateResponseSchema) {
    static _OPENAPI_METADATA_FACTORY() {
        return {};
    }
}
exports.PluginTemplateResponseDto = PluginTemplateResponseDto;
const mapTemplate = (plugin, template) => {
    return {
        key: (0, workflow_1.asPluginKey)({ pluginName: plugin.name, name: template.name }),
        title: template.title,
        description: template.description,
        trigger: template.trigger,
        steps: template.steps.map((step) => ({
            method: step.method,
            config: step.config ?? null,
            enabled: step.enabled,
        })),
        uiHints: template.uiHints ?? [],
    };
};
exports.mapTemplate = mapTemplate;
function mapPlugin(plugin) {
    return {
        id: plugin.id,
        name: plugin.name,
        title: plugin.title,
        description: plugin.description,
        author: plugin.author,
        version: plugin.version,
        createdAt: plugin.createdAt.toISOString(),
        updatedAt: plugin.updatedAt.toISOString(),
        methods: plugin.methods.map((method) => (0, exports.mapMethod)(method)),
    };
}
const mapMethod = (method) => {
    return {
        key: (0, workflow_1.asPluginKey)({ pluginName: method.pluginName, name: method.name }),
        name: method.name,
        title: method.title,
        hostFunctions: method.hostFunctions,
        uiHints: method.uiHints,
        description: method.description,
        types: method.types,
        schema: method.schema,
    };
};
exports.mapMethod = mapMethod;
//# sourceMappingURL=plugin.dto.js.map