"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 messageStrategyService = __importStar(require("../services/messageStrategyService"));
class MessageStrategyController {
    /**
     * @route GET /api/message-strategies
     * @desc 获取所有消息策略
     * @access Private
     */
    async getStrategies(req, res) {
        try {
            const strategies = await messageStrategyService.getStrategies();
            return res.status(200).json(strategies);
        }
        catch (error) {
            console.error("获取消息策略失败:", error);
            return res.status(500).json({ success: false, message: "无法获取消息策略列表。" });
        }
    }
    /**
     * @route GET /api/message-strategy/:id
     * @desc 根据ID获取单个消息策略
     * @access Private
     */
    async getStrategyById(req, res) {
        try {
            const { id } = req.params;
            const strategy = await messageStrategyService.getStrategyById(id);
            if (!strategy) {
                return res.status(404).json({ success: false, message: "消息策略未找到。" });
            }
            return res.status(200).json({ success: true, data: strategy });
        }
        catch (error) {
            console.error(`获取消息策略失败 (ID: ${req.params.id}):`, error);
            return res.status(500).json({ success: false, message: "无法获取消息策略。" });
        }
    }
    /**
     * @route POST /api/message-strategy
     * @desc 创建一个新的消息策略
     * @access Private
     */
    async createStrategy(req, res) {
        try {
            const strategyData = req.body;
            const newStrategy = await messageStrategyService.createStrategy(strategyData);
            return res.status(201).json({ success: true, data: newStrategy });
        }
        catch (error) {
            console.error("创建消息策略失败:", error);
            return res.status(500).json({ success: false, message: "创建消息策略失败。" });
        }
    }
    /**
     * @route PUT /api/message-strategy/:id
     * @desc 更新一个消息策略
     * @access Private
     */
    async updateStrategy(req, res) {
        try {
            const { id } = req.params;
            const updateData = req.body;
            const updatedStrategy = await messageStrategyService.updateStrategy(id, updateData);
            if (!updatedStrategy) {
                return res.status(404).json({ success: false, message: "消息策略未找到。" });
            }
            return res.status(200).json({ success: true, data: updatedStrategy });
        }
        catch (error) {
            console.error(`更新消息策略失败 (ID: ${req.params.id}):`, error);
            return res.status(500).json({ success: false, message: "更新消息策略失败。" });
        }
    }
    /**
     * @route DELETE /api/message-strategy/:id
     * @desc 删除一个消息策略
     * @access Private
     */
    async deleteStrategy(req, res) {
        try {
            const { id } = req.params;
            const deletedStrategy = await messageStrategyService.deleteStrategy(id);
            if (!deletedStrategy) {
                return res.status(404).json({ success: false, message: "消息策略未找到。" });
            }
            return res.status(200).json({ success: true, message: "消息策略已成功删除。" });
        }
        catch (error) {
            console.error(`删除消息策略失败 (ID: ${req.params.id}):`, error);
            return res.status(500).json({ success: false, message: "删除消息策略失败。" });
        }
    }
}
exports.default = new MessageStrategyController();
