import { describe, it, expect, vi } from 'vitest';
import { PgStoreRepository } from '../infrastructure/pg-store-repository.js';
import type { PosStoreRepository } from '../domain/ports.js';
import { ListStoresUseCase } from '../application/list-stores.js';

const mockStore: import('../domain/store.js').PosStore = {
  id: '11111111-1111-1111-1111-111111111111',
  name: 'Tienda 1',
  slug: 'tienda-1',
  address: 'Calle Falsa 123',
  taxId: 'B12345678',
  contactEmail: 'tienda1@test.com',
  contactPhone: '600000001',
  receiptHeader: 'Tienda 1',
  receiptFooter: 'Gracias',
  settings: {},
  active: true,
  createdAt: new Date('2026-01-01'),
  updatedAt: new Date('2026-01-01'),
};

describe('ListStoresUseCase', () => {
  it('returns stores list with total', async () => {
    const repo = {
      list: vi.fn().mockResolvedValue({ stores: [mockStore], total: 1 }),
    } as unknown as PosStoreRepository;
    const uc = new ListStoresUseCase(repo);
    const result = await uc.execute({ active: true });
    expect(result.stores).toHaveLength(1);
    expect(result.total).toBe(1);
    expect(result.stores[0]?.name).toBe('Tienda 1');
  });

  it('passes options to repository', async () => {
    const repo = {
      list: vi.fn().mockResolvedValue({ stores: [], total: 0 }),
    } as unknown as PosStoreRepository;
    const uc = new ListStoresUseCase(repo);
    await uc.execute({ active: false, limit: 10, offset: 5 });
    expect(repo.list).toHaveBeenCalledWith({ active: false, limit: 10, offset: 5 });
  });
});
