'use strict';

const PROVIDER = 'portal_autofactura';

const PERMISSIONS = {
  DASHBOARD_VIEW: 'billing.dashboard.view',
  TICKETS_VIEW: 'billing.tickets.view',
  INVOICES_VIEW: 'billing.invoices.view',
  INVOICES_CREATE: 'billing.invoices.create',
  INVOICES_CANCEL: 'billing.invoices.cancel',
  GLOBAL_CREATE: 'billing.global.create',
  MANUAL_CREATE: 'billing.manual.create',
  REPORTS_VIEW: 'billing.reports.view',
};

const INVOICE_STATUS = {
  PENDING: 'pending',
  INVOICED: 'invoiced',
  CANCELLED: 'cancelled',
  CANCEL_REQUESTED: 'cancel_requested',
};

const ENVIRONMENTS = ['sandbox', 'production'];

const EXTERNAL_CONTRACT = {
  auth: 'POST configurable por integrador',
  health: 'GET /api/v1/health',
  dashboard: 'GET /api/v1/dashboard',
  tickets: 'GET /api/v1/tickets',
  pendingTickets: 'GET /api/v1/tickets/pending',
  invoicedTickets: 'GET /api/v1/tickets/invoiced',
  stampTicket: 'POST /api/v1/tickets/{external_ticket_id}/invoice',
  manualInvoice: 'POST /api/v1/invoices/manual',
  globalInvoice: 'POST /api/v1/invoices/global',
  cancelInvoice: 'POST /api/v1/invoices/{uuid}/cancel',
  pdf: 'GET /api/v1/invoices/{uuid}/pdf',
  xml: 'GET /api/v1/invoices/{uuid}/xml',
  email: 'POST /api/v1/invoices/{uuid}/email',
  reports: 'GET /api/v1/reports/{type}',
};

const MICFDI_CONTRACT = {
  provider: 'GA Solutions / Portal de AutoFactura',
  baseUrl: 'https://micfdi.site/ws/api_timbrado.php',
  authMode: 'login',
  authPath: '?endpoint=login',
  tokenField: 'token',
  login: 'POST ?endpoint=login',
  stamp: 'POST ?endpoint=timbrar',
  global: 'POST ?endpoint=global',
  cancel: 'POST ?endpoint=cancelar',
  branch: 'GET ?endpoint=sucursal',
  tokenTtlSeconds: 3600,
  stampPayload: {
    monto: 'Total con IVA incluido',
    formapago: '01 efectivo, 04 tarjeta credito, 28 tarjeta debito, 03 transferencia, 29 SPEI',
    rfccliente: 'RFC receptor',
    razonsocial: 'Nombre fiscal exacto del receptor',
    usocfdi: 'S01 sin efectos, G03 gastos generales, G01 adquisicion mercancias',
    codigopostalcliente: 'CP fiscal receptor',
    regimenfiscal: 'Regimen fiscal receptor, default 616',
    serie: 'Serie del comprobante, default A',
    concepto: 'Descripcion del concepto, default Venta',
    claveprodserv: 'Opcional; default configurado en sucursal',
  },
};

module.exports = {
  PROVIDER,
  PERMISSIONS,
  INVOICE_STATUS,
  ENVIRONMENTS,
  EXTERNAL_CONTRACT,
  MICFDI_CONTRACT,
};
