"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const router_1 = __importDefault(require("@koa/router"));
const audioedit_service_1 = require("./audioedit.service");
const router = new router_1.default();
/**
 * 裁剪音频
 * POST /api/audio/trim
 */
router.post('/trim', async (ctx) => {
    try {
        const { audioId, startTime, endTime } = ctx.request.body;
        if (!audioId || startTime === undefined || endTime === undefined) {
            ctx.body = {
                code: 400,
                message: '缺少必填字段',
            };
            return;
        }
        if (startTime >= endTime) {
            ctx.body = {
                code: 400,
                message: '起始时间必须小于结束时间',
            };
            return;
        }
        const result = await audioedit_service_1.audioEditService.trimAudio(audioId, startTime, endTime);
        ctx.body = {
            code: 0,
            message: 'success',
            data: result,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '裁剪失败',
        };
    }
});
/**
 * 合并音频
 * POST /api/audio/merge
 */
router.post('/merge', async (ctx) => {
    try {
        const { audioIds, order } = ctx.request.body;
        if (!audioIds || audioIds.length < 2) {
            ctx.body = {
                code: 400,
                message: '至少需要两个音频才能合并',
            };
            return;
        }
        const mergeOrder = order || audioIds.map((_, i) => i);
        const result = await audioedit_service_1.audioEditService.mergeAudios(audioIds, mergeOrder);
        ctx.body = {
            code: 0,
            message: 'success',
            data: result,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '合并失败',
        };
    }
});
/**
 * 获取音频信息
 * GET /api/audio/:audioId/info
 */
router.get('/:audioId/info', async (ctx) => {
    try {
        const { audioId } = ctx.params;
        const result = await audioedit_service_1.audioEditService.getAudioInfo(audioId);
        ctx.body = {
            code: 0,
            message: 'success',
            data: result,
        };
    }
    catch (error) {
        ctx.body = {
            code: 400,
            message: error.message || '获取音频信息失败',
        };
    }
});
exports.default = router;
