const sendinblueHelper = require("./sendinblue.helper");


function sendTicket(header, values) {
  const body = {
    TemplateID: 179,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      tipoEntrada: values.tipoEntrada,
      descriptionEntrada: values.descriptionEntrada,
      qrCode: values.qrCode,
      qrCodeUrl: values.qrCodeUrl,
      //"IDqrCode": "cid:id1",
      codeTicket: values.codeTicket,
      idTicket: String(values.idTicket),
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      dateInscription: values.dateInscription,
      color: values.color ? values.color : "green",
      nameInscription: header.name,
    },

    /*"InlinedAttachments": [
            {
                "ContentType": "image/png",
                "Filename": "qr.png",
                "ContentID": "id1",
                "Content-Disposition": "inline",
                "Base64Content": values.qrCode.substr(22)  //Quitamos la cabecera para quedarnos solo con la imagen
            },
        ],*/
  };
  //console.log('>>>>>>>>>>>>>>>>>>><<SendTicket>>>', body);
  return sendinblueHelper.sendEmailTransactional(header, body);
}

function sendTicketOnline(header, values) {
  const body = {
    TemplateID: 177,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      tipoEntrada: values.tipoEntrada,
      descriptionEntrada: values.descriptionEntrada,
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      dateInscription: values.dateInscription,
      color: values.color ? values.color : "green",
      nameInscription: header.name,
    },
  };

  //console.log('>>>>>>>>>>>>>>>>>>><<VALUES ONLINE>>>', values);
  return sendinblueHelper.sendEmailTransactional(header, body);
}

function sendPendienteConfirmacion(header, values) {
  const body = {
    TemplateID: 323,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      tipoEntrada: values.tipoEntrada,
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      dateInscription: values.dateInscription,
      color: values.color ? values.color : "green",
      nameInscription: header.name,
      idTicket: String(values.idTicket),      
    },
  };

console.log('>>>>>>>>>>>>>>>>>>><<VALUES RESERVATION PENDIENTE CONFIRM>>>', values);  
  return sendinblueHelper.sendEmailTransactional(header, body);
}

function sendListaEspera(header, values) {
  const body = {
    TemplateID: 180,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      tipoEntrada: values.tipoEntrada,
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      dateInscription: values.dateInscription,
      color: values.color ? values.color : "green",
      nameInscription: header.name,
      idTicket: String(values.idTicket),
    },
  };

  console.log('>>>>>>>>>>>>>>>>>>><<sendListaEspera>>>', body);  
  return sendinblueHelper.sendEmailTransactional(header, body);
}

function sendReservationCode(header, values) {
  const body = {
    TemplateID: 182,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      entityName: values.entityName,
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      reservationCode: values.reservationCode,
      reservationDescription: values.reservationDescription ? values.reservationDescription : "-",
    },
  };
  //  console.log('sendReservationCode >>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<', header, body)
  return sendinblueHelper.sendEmailTransactional(header, body);
}

function sendReservationCodeCollege(header, values) {
  const body = {
    TemplateID: 181,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      entityName: values.entityName,
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      reservationCode: values.reservationCode,
      reservationDescription: values.reservationDescription ? values.reservationDescription : "-",
    },
  };
  //  console.log('sendReservationCodeCollege >>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<', header, body)
  return sendinblueHelper.sendEmailTransactional(header, body);
}

function sendCancelacion(header, values) {
  const body = {
    TemplateID: 183,
    TemplateLanguage: true,
    TemplateErrorDeliver: true,
    TemplateErrorReporting: {
      Email: "info@rodax-software.com",
      Name: "Air traffic control",
    },
    Variables: {
      tipoEntrada: values.tipoEntrada,
      eventName: values.eventName,
      dateEvent: values.dateEvent,
      dateInscription: values.dateInscription,
      color: values.color ? values.color : "green",
      nameInscription: header.name,
    },
  };

  return sendinblueHelper.sendEmailTransactional(header, body);
}

/**
 * Enviar un email
 * @header
 *   @param {number} data.to - Email destino
 *   @param {number} data.name - Nombre del contacto destino
 *   @param {number} data.subject - Asunto
 * @subjectAnBody
 *   @param {number} data.text - Cuerpo del mensaje en texto plano
 *   @param {number} data.html - Cuerpo del mensaje en HTML
 * @return {Promise}
 *
 */
function sendMail(header, values) {
  const body = {
    TextPart: values.text,
    HTMLPart: values.html,
  };

  return sendinblueHelper.sendEmailTransactional(header, body);
}

module.exports = {
  sendMail,
  sendTicket,
  sendListaEspera,
  sendCancelacion,
  sendReservationCode,
  sendReservationCodeCollege,
  sendTicketOnline,
  sendPendienteConfirmacion,
};
