const axios = require('axios');

module.exports = {
  zuckbotconfig: {
    name: "checkscam",
    info: "Kiểm tra số điện thoại scam",
    role: 200,
    Category
    usage: "[số điện thoại]",
    cooldown: 5
  },

  onRun: async function({ api, event }) {
    const { threadID, messageID, body } = event;

    const phoneNumberRegex = /^\d+$/;
    if (!phoneNumberRegex.test(body)) return;

    try {
      const response = await axios.get(`https://${global.settings?.LINKAPI}/api/scam?phone=${body}`);
      const data = response.data;
      
      let msg = `📱 Kết quả kiểm tra số ${body}:\n\n`;
      
      if (data.status === "success") {
        if (data.data && data.data.length > 0) {
          msg += "⚠️ CẢNH BÁO: Số điện thoại này đã bị báo cáo scam!\n\n";
          msg += `🔍 Số lần bị báo cáo: ${data.data.length}\n`;
          msg += "📝 Chi tiết báo cáo:\n";
          
          data.data.forEach((report, index) => {
            msg += `\n${index + 1}. ${report.content}\n`;
            msg += `   Thời gian: ${report.time}\n`;
          });
        } else {
          msg += "✅ Số điện thoại này chưa có báo cáo scam nào.";
        }
      } else {
        msg += "❌ Không thể kiểm tra. Vui lòng thử lại sau.";
      }
      
      api.sendMessage(msg, threadID, messageID);
    } catch (error) {
      console.error("Error checking scam:", error);
      api.sendMessage("❌ Đã có lỗi xảy ra khi kiểm tra. Vui lòng thử lại sau.", threadID, messageID);
    }
  }
};