const { sendMessage, sendPhoto } = require('../api');
const { safeExec } = require('../helpers');

const sendMsgTelegram = safeExec(async (user, text) => {
  if (!user || !user.telegram_id) return null;
  return sendMessage(user.telegram_id, text);
});

const sendMsgTelegramByIdTelegram = safeExec(async (telegramId, text) => {
  if (!telegramId) return null;
  return sendMessage(telegramId, text);
});

const sendPhotoTelegram = safeExec(async (chatIdOrUser, photoUrl, caption = '') => {
  const chatId = typeof chatIdOrUser === 'object' ? chatIdOrUser?.telegram_id : chatIdOrUser;
  if (!chatId || !photoUrl) return null;
  return sendPhoto(chatId, photoUrl, caption);
});

module.exports = {
  sendMsgTelegram,
  sendMsgTelegramByIdTelegram,
  sendPhotoTelegram,
};
