import { Injectable } from '@nestjs/common';
import axios from 'axios';

@Injectable()
export class EmailTemporaryAppointmentService {
  async temporary_appointment(email: string, name: string, Hosname: string, date_time: string, TEM_APP_NO: string, company: string) {
    const url = process.env.MSG_EMAIL_SEND_EMAIL_API;


    const headers = {
      accept: 'application/json',
      'content-type': 'application/json',
      authkey: process.env.MSG_EMAIL_SEND_EMAIL_AUTHKEY
    }

    const data = {
      "recipients": [
        {
          "to": [
            {
              "email": email,
              "name": name
            }
          ],
          "variables": { "var": name, "var1": Hosname, "var2": date_time, "var3": TEM_APP_NO, "var4": company }
        }
      ],
      "from": {
        "email": process.env.MSG_EMAIL_SEND_EMAIL_FROM_EMAIL
      },
      "domain": process.env.MSG_EMAIL_SEND_EMAIL_DOMAIN,
      "template_id": process.env.MSG_TEMP_APPT_TEMPLATE_ID
    }
    try {
      const response = await axios.post(url, data, { headers });
      return response.data;
    } catch (error) {
      return error;
    }
  }

}
