import { Injectable } from '@nestjs/common';
import axios from 'axios';

@Injectable()
export class AppointmentNoSendService {
  async appointment_no(email: string, name: string, Hosname: string, date_time: string, appoint_no: string, location: string) {
    const url = `https://control.msg91.com/api/v5/email/send`;


    const headers = {
      accept: 'application/json',
      'content-type': 'application/json',
      authkey: '403400AF0OnTHLXvN691d649fP1'
    }

    const data = {
      "recipients": [
        {
          "to": [
            {
              "email": email,
              "name": name
            }
          ],
          "variables": { "var": name, "var1": Hosname, "var2": date_time, "var3": appoint_no, "var4": location }
        }
      ],
      "from": {
        "email": "no_reply@plenome.com"
      },
      "domain": "plenome.com",
      "template_id": "appointment_no_send"
    }
    try {

      console.log(data, "data");

      const response = await axios.post(url, data, { headers });

      return response.data;
    } catch (error) {
      console.log(error);

      return error;

    }
  }
}