import { describe, expect, it, vi, type Mock } from 'vitest';
import { PayerType, PaymentType } from '../../domain/entities/Payment';
import type { PaymentRepository } from '../../domain/repositories/PaymentRepository';
import { GetPaymentsUseCase, type GetPaymentsInput } from './GetPaymentsUseCase';

describe('GetPaymentsUseCase', () => {
  let paymentRepository: {
    findByFilters: Mock;
  };
  let useCase: GetPaymentsUseCase;

  beforeEach(() => {
    paymentRepository = {
      findByFilters: vi.fn(),
    };

    useCase = new GetPaymentsUseCase(
      paymentRepository as unknown as PaymentRepository,
    );
  });

  it('retrieves payments and returns result', async () => {
    const input: GetPaymentsInput = {
      leagueId: 'league-1',
      payerId: 'payer-1',
      type: PaymentType.SPONSORSHIP,
    };

    const payments = [
      {
        id: 'payment-1',
        type: PaymentType.SPONSORSHIP,
        amount: 100,
        platformFee: 5,
        netAmount: 95,
        payerId: 'payer-1',
        payerType: PayerType.SPONSOR,
        leagueId: 'league-1',
        seasonId: 'season-1',
        status: 'completed',
        createdAt: new Date(),
        completedAt: new Date(),
      },
    ];

    paymentRepository.findByFilters.mockResolvedValue(payments);

    const result = await useCase.execute(input);

    expect(result.isOk()).toBe(true);
    expect(paymentRepository.findByFilters).toHaveBeenCalledWith({
      leagueId: 'league-1',
      payerId: 'payer-1',
      type: PaymentType.SPONSORSHIP,
    });
    
    if (result.isOk()) {
      expect(result.value).toEqual({ payments });
    }
  });
});