import axios from "axios";
import { whatsappLog } from "../../serviceLog";
import CONSTANTS from "../../../config/constants";

const sendOTPSMS = async (mobile: string, msg: string,) => {
  try {

    let finalMsg = `${msg} is your verification code for Kipinn, valid for 15 min. Please do not share with others. THINK STRAIGHT INFORMATION TECHNOLOGY LLP.`

    let url = `http://nimbusit.net/api/pushsms?user=thinkstraightnet&authkey=92bpgwIRCLKeU&sender=${process.env.SMS_SENDER}&mobile=${mobile}&entityid=1701158045595586798&templateid=${CONSTANTS.SMS_TEMPLATE_IDS.OTP}&text=${finalMsg}`;

    const { data }: any = await axios.get(url, {timeout: 5000});
    
    whatsappLog.info(`[sendOTPSMS], Mobile [${mobile}], Response: ${JSON.stringify(data)}`);

    return true;
  } catch (error: any) {
    whatsappLog.info(
      `[sendOTPSMS], Mobile [${mobile}], Error: ${
        JSON.stringify(error?.response?.data) || error?.message || error
      }`
    );

    return false;
  }
};

export default sendOTPSMS;
