import {
  bookingCancelledHtml,
  bookingConfirmationHtml,
  bookingNoShowHtml,
} from '@/emails/booking-confirmation';
import { sendMail } from '@/lib/mailer';

type BookingEmailInput = {
  bookingCode: string;
  complexSlug?: string;
  complexName: string;
  date: string;
  startTime: string;
  endTime: string;
  courtName: string;
  sportName: string;
  customerName: string;
  customerEmail: string;
  price?: number;
};

export async function sendBookingConfirmation(data: BookingEmailInput) {
  if (!data.customerEmail) return;

  const html = bookingConfirmationHtml({
    bookingCode: data.bookingCode,
    complexSlug: data.complexSlug,
    complexName: data.complexName,
    date: data.date,
    startTime: data.startTime,
    endTime: data.endTime,
    courtName: data.courtName,
    sportName: data.sportName,
    customerName: data.customerName,
    price: data.price,
  });

  await sendMail({
    to: data.customerEmail,
    subject: `Reserva confirmada en ${data.complexName} | Playzer`,
    html,
    text: `Reserva confirmada en ${data.complexName}. Codigo: ${data.bookingCode}. Cancha: ${data.courtName}. Fecha: ${data.date}. Horario: ${data.startTime} - ${data.endTime}.`,
  });
}

export async function sendBookingCancelled(data: BookingEmailInput) {
  if (!data.customerEmail) return;

  const html = bookingCancelledHtml({
    bookingCode: data.bookingCode,
    complexName: data.complexName,
    date: data.date,
    startTime: data.startTime,
    endTime: data.endTime,
    courtName: data.courtName,
    sportName: data.sportName,
    customerName: data.customerName,
  });

  await sendMail({
    to: data.customerEmail,
    subject: `Reserva cancelada en ${data.complexName} | Playzer`,
    html,
    text: `Reserva cancelada en ${data.complexName}. Codigo: ${data.bookingCode}. Fecha: ${data.date}. Horario: ${data.startTime} - ${data.endTime}.`,
  });
}

export async function sendBookingNoShow(data: BookingEmailInput) {
  if (!data.customerEmail) return;

  const html = bookingNoShowHtml({
    bookingCode: data.bookingCode,
    complexName: data.complexName,
    date: data.date,
    startTime: data.startTime,
    endTime: data.endTime,
    courtName: data.courtName,
    sportName: data.sportName,
    customerName: data.customerName,
  });

  await sendMail({
    to: data.customerEmail,
    subject: `Reserva no concretada en ${data.complexName} | Playzer`,
    html,
    text: `Reserva no concretada en ${data.complexName}. Codigo: ${data.bookingCode}. Fecha: ${data.date}. Horario: ${data.startTime} - ${data.endTime}.`,
  });
}
