import { crearIntegracionMock } from './__helpers__/integracion-mock';
import { repartoProporcional } from '../../nota-credito-compras/reglas-nc-compra';

// Asiento de la NC de compra según su origen (plan 2026-10-22-nc-compra, Task 6):
// contra compra igual que siempre; contra gasto acredita las mismas cuentas y
// dimensiones del asiento vigente del gasto, en proporción; sin origen va a la
// cuenta que el contador mapeó en NC_COMPRA_SIN_ORIGEN.

const lineas = (s: any) => s.asientos.crearConfirmado.mock.calls[0][3].lineas;
const sumaDebe = (ls: any[]) => ls.reduce((a: number, l: any) => a + l.debe_moneda, 0);
const sumaHaber = (ls: any[]) => ls.reduce((a: number, l: any) => a + l.haber_moneda, 0);

const ncBase = {
  id: 'nc1', empresa_id: 'emp', compra_id: null, gasto_id: null, proveedor_id: 'p1', moneda: { codigo: 'PYG' }, cotizacion: null,
  fecha_emision: new Date('2026-10-22'), total: 550, total_iva_10: 50, total_iva_5: 0, establecimiento: '001', punto_expedicion: '001', numero: '7',
  usuario_id: 'u1', compra_cab: null,
};

/** Asiento vigente de un gasto de 1100: 600 + 400 a dos cuentas, 100 de IVA y el proveedor. */
const asientoGasto = {
  asiento: {
    moneda_origen: 'PYG',
    lineas: [
      { cuenta_id: 'cta-600', debe_moneda: 600, haber_moneda: 0, centro_costo_id: 'cc-1', mapeo_concepto: 'FICHA_TIPO_GASTO', mapeo_regla_id: null, mapeo_nivel: 'FICHA' },
      { cuenta_id: 'cta-400', debe_moneda: 400, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'GASTOS_GENERALES', mapeo_regla_id: 'r-9', mapeo_nivel: 'REGLA' },
      { cuenta_id: 'cta-IVA_CREDITO_10', debe_moneda: 100, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'IVA_CREDITO_10', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
      { cuenta_id: 'cta-PROVEEDORES', debe_moneda: 0, haber_moneda: 1100, centro_costo_id: null, mapeo_concepto: 'PROVEEDORES', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
    ],
  },
};

const mock = (nc: any, opciones: { faltan?: string[]; docGasto?: any } = {}) => {
  const s = crearIntegracionMock(
    {
      nota_credito_compra_cab: { findUnique: jest.fn().mockResolvedValue(nc) },
      cont_documentos: {
        findFirst: jest.fn().mockImplementation(async ({ where }: any) => (where.origen_tipo === 'gasto_cab' ? opciones.docGasto ?? null : null)),
        create: jest.fn().mockResolvedValue({ id: 'd' }),
        upsert: jest.fn().mockResolvedValue({ id: 'd' }),
        update: jest.fn().mockResolvedValue({}),
      },
    },
    opciones.faltan ?? [],
  );
  s.resolverCuentaPasivo = jest.fn().mockResolvedValue('cta-PROVEEDORES');
  return s;
};

describe('asiento de la NC de compra según el origen', () => {
  it('contra compra: igual que hoy (snapshot de líneas)', async () => {
    const s = mock({ ...ncBase, compra_id: 'c1', compra_cab: { sucursal_id: null } });
    await s.integrarNotaCreditoCompra('nc1');
    expect(lineas(s)).toEqual([
      { cuenta_id: 'cta-PROVEEDORES', debe_moneda: 550, haber_moneda: 0, descripcion: 'Proveedor (NC compra)' },
      { cuenta_id: 'cta-INVENTARIO', debe_moneda: 0, haber_moneda: 500, descripcion: 'Reversión Inventario/Gasto', mapeo_concepto: 'INVENTARIO', mapeo_nivel: 'DEFECTO' },
      { cuenta_id: 'cta-IVA_CREDITO_10', debe_moneda: 0, haber_moneda: 50, descripcion: 'Reversión IVA Crédito 10%', mapeo_concepto: 'IVA_CREDITO_10', mapeo_nivel: 'DEFECTO' },
    ]);
  });

  it('contra gasto con dos cuentas 600/400 y NC por la mitad del neto: haber 300/200 con las dimensiones del gasto', async () => {
    const s = mock({ ...ncBase, gasto_id: 'g1' }, { docGasto: asientoGasto });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-600')).toMatchObject({
      debe_moneda: 0, haber_moneda: 300, centro_costo_id: 'cc-1', mapeo_concepto: 'FICHA_TIPO_GASTO', mapeo_nivel: 'FICHA',
    });
    expect(ls.find((l: any) => l.cuenta_id === 'cta-400')).toMatchObject({
      debe_moneda: 0, haber_moneda: 200, centro_costo_id: null, mapeo_concepto: 'GASTOS_GENERALES', mapeo_regla_id: 'r-9', mapeo_nivel: 'REGLA',
    });
    // El IVA sale de la NC (no del gasto) y el proveedor va al debe.
    expect(ls.filter((l: any) => l.cuenta_id === 'cta-IVA_CREDITO_10')).toEqual([expect.objectContaining({ haber_moneda: 50 })]);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-PROVEEDORES')).toMatchObject({ debe_moneda: 550, haber_moneda: 0 });
    expect(ls.map((l: any) => l.cuenta_id)).not.toContain('cta-INVENTARIO');
    expect(sumaHaber(ls)).toBe(sumaDebe(ls));
    // Lee solo el asiento vigente del gasto.
    expect(s.prisma.cont_documentos.findFirst).toHaveBeenCalledWith(
      expect.objectContaining({
        where: expect.objectContaining({ empresa_id: 'emp', origen_tipo: 'gasto_cab', origen_id: 'g1', estado: 'CONFIRMADO', asiento: { estado: 'CONFIRMADO' } }),
      }),
    );
  });

  it('contra gasto sin asiento vigente: no hay asiento y queda el aviso', async () => {
    const s = mock({ ...ncBase, gasto_id: 'g1' }, { docGasto: null });
    await s.integrarNotaCreditoCompra('nc1');
    expect(s.asientos.crearConfirmado).not.toHaveBeenCalled();
    expect(s.avisosMapeo.registrarFaltaMapeo).toHaveBeenCalledWith(
      expect.objectContaining({
        empresaId: 'emp',
        origenTipo: 'nota_credito_compra_cab',
        origenId: 'nc1',
        conceptos: ['ASIENTO_GASTO_ORIGEN'],
        // Motivo propio: no es falta de mapeo (Conciliación no manda a Mapeo de cuentas).
        motivo: 'ASIENTO_ORIGEN',
        detalles: { ASIENTO_GASTO_ORIGEN: expect.stringMatching(/gasto de origen no tiene asiento vigente: asentá el gasto .*regenerá esta nota de crédito en Conciliación/) },
      }),
    );
  });

  it('contra gasto con asiento vigente pero sin líneas para revertir: aviso propio y sin asiento', async () => {
    const soloIva = { asiento: { moneda_origen: 'PYG', lineas: [asientoGasto.asiento.lineas[2], asientoGasto.asiento.lineas[3]] } };
    const s = mock({ ...ncBase, gasto_id: 'g1' }, { docGasto: soloIva });
    await s.integrarNotaCreditoCompra('nc1');
    expect(s.asientos.crearConfirmado).not.toHaveBeenCalled();
    const aviso = s.avisosMapeo.registrarFaltaMapeo.mock.calls[0][0];
    expect(aviso.conceptos).toEqual(['ASIENTO_GASTO_ORIGEN']);
    expect(aviso.motivo).toBe('ASIENTO_ORIGEN');
    expect(aviso.detalles.ASIENTO_GASTO_ORIGEN).toMatch(/asiento del gasto de origen no tiene líneas para revertir/);
    expect(aviso.detalles.ASIENTO_GASTO_ORIGEN).not.toMatch(/no tiene asiento vigente/);
  });

  it('contra gasto con asiento anterior a la traza: el IVA se reconoce por la cuenta de IVA crédito', async () => {
    const viejo = {
      asiento: {
        moneda_origen: 'PYG',
        lineas: asientoGasto.asiento.lineas.map((l) => ({ ...l, mapeo_concepto: null, mapeo_regla_id: null, mapeo_nivel: null })),
      },
    };
    const s = mock({ ...ncBase, gasto_id: 'g1' }, { docGasto: viejo });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-600').haber_moneda).toBe(300);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-400').haber_moneda).toBe(200);
    // La línea vieja de IVA no se acredita como gasto: el IVA es el de la NC.
    expect(ls.filter((l: any) => l.cuenta_id === 'cta-IVA_CREDITO_10')).toEqual([expect.objectContaining({ haber_moneda: 50, mapeo_concepto: 'IVA_CREDITO_10' })]);
  });

  it('contra gasto no deducible con el IVA sumado al gasto: revierte el total en esa cuenta y sin IVA crédito', async () => {
    const sumado = {
      asiento: {
        moneda_origen: 'PYG',
        lineas: [
          { cuenta_id: 'cta-GASTO', debe_moneda: 1100, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'FICHA_TIPO_GASTO', mapeo_regla_id: null, mapeo_nivel: 'FICHA' },
          { cuenta_id: 'cta-PROVEEDORES', debe_moneda: 0, haber_moneda: 1100, centro_costo_id: null, mapeo_concepto: 'PROVEEDORES', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
        ],
      },
    };
    const s = mock({ ...ncBase, gasto_id: 'g1' }, { docGasto: sumado });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.filter((l: any) => l.haber_moneda > 0)).toEqual([expect.objectContaining({ cuenta_id: 'cta-GASTO', haber_moneda: 550 })]);
    expect(ls.map((l: any) => l.cuenta_id)).not.toContain('cta-IVA_CREDITO_10');
    expect(ls.find((l: any) => l.cuenta_id === 'cta-PROVEEDORES')).toMatchObject({ debe_moneda: 550 });
  });

  it('contra gasto no deducible con IVA_NO_DEDUCIBLE en cuenta propia: se revierte proporcional en esa cuenta', async () => {
    const aparte = {
      asiento: {
        moneda_origen: 'PYG',
        lineas: [
          { cuenta_id: 'cta-GASTO', debe_moneda: 1000, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'FICHA_TIPO_GASTO', mapeo_regla_id: null, mapeo_nivel: 'FICHA' },
          { cuenta_id: 'cta-IVA_NO_DEDUCIBLE', debe_moneda: 100, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'IVA_NO_DEDUCIBLE', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
          { cuenta_id: 'cta-PROVEEDORES', debe_moneda: 0, haber_moneda: 1100, centro_costo_id: null, mapeo_concepto: 'PROVEEDORES', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
        ],
      },
    };
    const s = mock({ ...ncBase, gasto_id: 'g1' }, { docGasto: aparte });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-GASTO')).toMatchObject({ haber_moneda: 500 });
    expect(ls.find((l: any) => l.cuenta_id === 'cta-IVA_NO_DEDUCIBLE')).toMatchObject({ haber_moneda: 50, mapeo_concepto: 'IVA_NO_DEDUCIBLE' });
    expect(ls.map((l: any) => l.cuenta_id)).not.toContain('cta-IVA_CREDITO_10');
    expect(sumaHaber(ls)).toBe(550);
    expect(sumaDebe(ls)).toBe(550);
  });

  it('PYG: NC de 1000 al 10% contra gasto con IVA crédito → DEBE = HABER exacto, todo en enteros', async () => {
    // IVA de la NC grabado con 2 decimales (90.91): en PYG se redondea a 91 y la reversión lleva el resto.
    const s = mock({ ...ncBase, gasto_id: 'g1', total: 1000, total_iva_10: 90.91 }, { docGasto: asientoGasto });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-PROVEEDORES').debe_moneda).toBe(1000);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-IVA_CREDITO_10').haber_moneda).toBe(91);
    expect(ls.every((l: any) => Number.isInteger(l.debe_moneda) && Number.isInteger(l.haber_moneda))).toBe(true);
    // 909 en proporción 600/400: 545.4 / 363.6 → 545 / 364 (residuo a la mayor).
    expect(ls.find((l: any) => l.cuenta_id === 'cta-600').haber_moneda + ls.find((l: any) => l.cuenta_id === 'cta-400').haber_moneda).toBe(909);
    expect(sumaHaber(ls)).toBe(sumaDebe(ls));
  });

  it('USD con cotización con decimales contra gasto con IVA crédito → DEBE = HABER exacto', async () => {
    const enBase = (n: number) => Math.round(n * 7312.37);
    const doc = {
      asiento: {
        moneda_origen: 'PYG',
        lineas: asientoGasto.asiento.lineas.map((l) => ({ ...l, debe_moneda: enBase(l.debe_moneda), haber_moneda: enBase(l.haber_moneda) })),
      },
    };
    const s = mock({ ...ncBase, gasto_id: 'g1', moneda: { codigo: 'USD' }, cotizacion: 7312.37, total: 123.45, total_iva_10: 11.22 }, { docGasto: doc });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-PROVEEDORES').debe_moneda).toBe(Math.round(123.45 * 7312.37));
    expect(ls.find((l: any) => l.cuenta_id === 'cta-IVA_CREDITO_10').haber_moneda).toBe(Math.round(11.22 * 7312.37));
    expect(ls.every((l: any) => Number.isInteger(l.debe_moneda) && Number.isInteger(l.haber_moneda))).toBe(true);
    expect(sumaHaber(ls)).toBe(sumaDebe(ls));
  });

  it('USD con cotización con decimales contra gasto sin IVA crédito → DEBE = HABER exacto', async () => {
    const doc = {
      asiento: {
        moneda_origen: 'PYG',
        lineas: [
          { cuenta_id: 'cta-GASTO', debe_moneda: 7000000, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'FICHA_TIPO_GASTO', mapeo_regla_id: null, mapeo_nivel: 'FICHA' },
          { cuenta_id: 'cta-IVA_NO_DEDUCIBLE', debe_moneda: 700000, haber_moneda: 0, centro_costo_id: null, mapeo_concepto: 'IVA_NO_DEDUCIBLE', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
          { cuenta_id: 'cta-PROVEEDORES', debe_moneda: 0, haber_moneda: 7700000, centro_costo_id: null, mapeo_concepto: 'PROVEEDORES', mapeo_regla_id: null, mapeo_nivel: 'DEFECTO' },
        ],
      },
    };
    const s = mock({ ...ncBase, gasto_id: 'g1', moneda: { codigo: 'USD' }, cotizacion: 7312.37, total: 123.45, total_iva_10: 11.22 }, { docGasto: doc });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.map((l: any) => l.cuenta_id)).not.toContain('cta-IVA_CREDITO_10');
    expect(ls.find((l: any) => l.cuenta_id === 'cta-PROVEEDORES').debe_moneda).toBe(Math.round(123.45 * 7312.37));
    expect(ls.every((l: any) => Number.isInteger(l.debe_moneda) && Number.isInteger(l.haber_moneda))).toBe(true);
    expect(sumaHaber(ls)).toBe(sumaDebe(ls));
  });

  it('sin origen con mapeo: haber en la cuenta de NC_COMPRA_SIN_ORIGEN', async () => {
    const s = mock(ncBase);
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.haber_moneda === 500)).toMatchObject({ cuenta_id: 'cta-NC_COMPRA_SIN_ORIGEN', mapeo_concepto: 'NC_COMPRA_SIN_ORIGEN' });
    expect(ls.map((l: any) => l.cuenta_id)).not.toContain('cta-INVENTARIO');
  });

  it('sin origen sin mapeo: aviso de mapeo y sin asiento', async () => {
    const s = mock(ncBase, { faltan: ['NC_COMPRA_SIN_ORIGEN'] });
    await s.integrarNotaCreditoCompra('nc1');
    expect(s.asientos.crearConfirmado).not.toHaveBeenCalled();
    expect(s.avisosMapeo.registrarFaltaMapeo).toHaveBeenCalledWith(
      expect.objectContaining({ origenTipo: 'nota_credito_compra_cab', origenId: 'nc1', conceptos: ['NC_COMPRA_SIN_ORIGEN'] }),
    );
  });

  it('USD 7300: debe/haber en moneda base multiplicados por la cotización', async () => {
    const s = mock({ ...ncBase, moneda: { codigo: 'USD' }, cotizacion: 7300, total: 110, total_iva_10: 10 });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-PROVEEDORES').debe_moneda).toBe(803000);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-NC_COMPRA_SIN_ORIGEN').haber_moneda).toBe(730000);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-IVA_CREDITO_10').haber_moneda).toBe(73000);
    expect(s.asientos.crearConfirmado.mock.calls[0][3].glosa).toMatch(/\[USD x 7300\]/);
  });

  it('USD contra gasto: el factor sale de los netos en moneda base', async () => {
    // Gasto de USD 1100 a 7000 asentado en moneda base; NC de USD 550 a 7000 → la mitad.
    const enBase = (n: number) => n * 7000;
    const doc = {
      asiento: {
        moneda_origen: 'PYG',
        lineas: asientoGasto.asiento.lineas.map((l) => ({ ...l, debe_moneda: enBase(l.debe_moneda), haber_moneda: enBase(l.haber_moneda) })),
      },
    };
    const s = mock({ ...ncBase, gasto_id: 'g1', moneda: { codigo: 'USD' }, cotizacion: 7000 }, { docGasto: doc });
    await s.integrarNotaCreditoCompra('nc1');
    const ls = lineas(s);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-600').haber_moneda).toBe(2100000);
    expect(ls.find((l: any) => l.cuenta_id === 'cta-400').haber_moneda).toBe(1400000);
  });
});

describe('repartoProporcional', () => {
  it('repartoProporcional suma exacto con redondeo', () => {
    const r = repartoProporcional(
      [
        { cuenta_id: 'a', monto: 100, dims: { x: 1 } },
        { cuenta_id: 'b', monto: 100, dims: null },
        { cuenta_id: 'c', monto: 101, dims: null },
      ],
      1 / 3,
      2,
    );
    const centavos = r.map((l) => Math.round(l.monto * 100));
    // 301/3 = 100.333… → 100.33 en total.
    expect(centavos.reduce((a, b) => a + b, 0)).toBe(Math.round((301 / 3) * 100));
    expect(r.map((l) => l.cuenta_id)).toEqual(['a', 'b', 'c']);
    expect(r[0].dims).toEqual({ x: 1 });
  });

  it('el residuo del redondeo va a la línea mayor', () => {
    // 3 × 33.333… = 99.99 redondeado por línea; el total es 100.00: el centavo va a la mayor.
    const r = repartoProporcional(
      [
        { cuenta_id: 'a', monto: 10, dims: null },
        { cuenta_id: 'b', monto: 10, dims: null },
        { cuenta_id: 'c', monto: 10.000001, dims: null },
      ],
      100 / 30.000001,
      2,
    );
    expect(r.map((l) => l.monto)).toEqual([33.33, 33.33, 33.34]);
    expect(Math.round(r.reduce((a, l) => a + l.monto, 0) * 100)).toBe(10000);
  });

  it('en PYG (0 decimales) con factor 1/3 da enteros y suma exacto', () => {
    const r = repartoProporcional(
      [
        { cuenta_id: 'a', monto: 1000, dims: null },
        { cuenta_id: 'b', monto: 1000, dims: null },
        { cuenta_id: 'c', monto: 1001, dims: null },
      ],
      1 / 3,
      0,
    );
    expect(r.every((l) => Number.isInteger(l.monto))).toBe(true);
    // 3001/3 = 1000.33 → 1000; 333 + 333 + 334 (la mayor lleva el residuo).
    expect(r.map((l) => l.monto)).toEqual([333, 333, 334]);
    expect(r.reduce((a, l) => a + l.monto, 0)).toBe(1000);
  });

  it('factor 1 devuelve los mismos montos', () => {
    expect(repartoProporcional([{ cuenta_id: 'a', monto: 600, dims: null }, { cuenta_id: 'b', monto: 400, dims: null }], 1, 0).map((l) => l.monto)).toEqual([600, 400]);
  });

  it('sin líneas devuelve vacío', () => {
    expect(repartoProporcional([], 0.5, 0)).toEqual([]);
  });
});

describe('precarga de NC_COMPRA_SIN_ORIGEN', () => {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const { ContabilidadSeedService } = require('./seed.service');
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const { MAPEO_DEFAULT } = require('../seeds/plan-cuentas-paraguay.seed');

  it('«mapeo faltantes» la crea como el resto de las precargas: sin origen ni confirmación (PRECARGA, sin confirmar por defecto)', async () => {
    const service = Object.create(ContabilidadSeedService.prototype) as any;
    service.logger = { log: jest.fn() };
    service.obtenerModulosActivos = jest.fn().mockResolvedValue(null);
    service.seedPlanCuentas = jest.fn().mockResolvedValue({ insertadas: 0, omitidas: 0 });
    const existentes = Object.keys(MAPEO_DEFAULT).filter((c) => c !== 'NC_COMPRA_SIN_ORIGEN' && c !== 'INVENTARIO').map((concepto) => ({ concepto }));
    service.prisma = {
      cont_mapeo_cuentas: { findMany: jest.fn().mockResolvedValue(existentes), create: jest.fn().mockResolvedValue({}), upsert: jest.fn() },
      cont_plan_cuentas: { findFirst: jest.fn().mockResolvedValue({ id: 'cta-mercaderias' }) },
    };
    const r = await service.seedMapeoFaltantes('emp');
    expect(r.conceptos).toEqual(['INVENTARIO', 'NC_COMPRA_SIN_ORIGEN']);
    const creadas = service.prisma.cont_mapeo_cuentas.create.mock.calls.map((c: any) => c[0].data);
    // La misma forma para los dos: origen y confirmación quedan en los defaults de la
    // migración 20261016000000_mapeo_constancia (origen PRECARGA, confirmado_at null).
    expect(creadas).toEqual([
      { empresa_id: 'emp', concepto: 'INVENTARIO', cuenta_id: 'cta-mercaderias' },
      { empresa_id: 'emp', concepto: 'NC_COMPRA_SIN_ORIGEN', cuenta_id: 'cta-mercaderias' },
    ]);
    expect(service.prisma.cont_plan_cuentas.findFirst).toHaveBeenCalledWith(
      expect.objectContaining({ where: { OR: [{ empresa_id: 'emp', codigo: '1.1.4.01' }, { empresa_id: null, codigo: '1.1.4.01' }] } }),
    );
  });
});
