import api from './api';

export const cashRegisterService = {
  // Obtener resumen y lista de transacciones de hoy
  getDailyStatus: async () => {
    const res = await api.get('/reports/cashier-transactions');
    return res.data; // Devuelve el GlobalReportDto
  },

  // Disparar la descarga del PDF de cierre
  downloadClosurePdf: async () => {
    const today = new Date().toISOString().split('T')[0];
    const res = await api.get('/reports/export-cierre', {
      params: { from: today, to: today },
      responseType: 'blob'
    });

    const url = window.URL.createObjectURL(new Blob([res.data], { type: 'application/pdf' }));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', `Cierre_Caja_${today}.pdf`);
    document.body.appendChild(link);
    link.click();
    link.remove();
  }
};