import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { MSG91CREDS } from 'config/msg91.config';

@Injectable()
export class SendMsg91PasswordService {
  async sendMsg91Password(
    country_phone_code: string,
    phone_number: string,
    password: any,
    username:any
  ) {
    try {
      const json={
              mobiles: `${country_phone_code.split('+')[1]}${phone_number}`,
              PASSWORD: password,
              USERNAME: username
            }
      const res = await axios.post(
        'https://control.msg91.com/api/v5/flow',
        {
          template_id: MSG91CREDS?.PASSWORD_TEMPLATE_ID,
          recipients: [json  ],
        },
        {
          headers: {
            authkey: MSG91CREDS?.AUTH_KEY,
            accept: 'application/json',
            'content-type': 'application/json',
          },
        },
      );
      console.log(res?.data);
      return true;
    } catch (error) {
      console.log(error);
      return false;
    }
  }
}
