import { describe, it, expect, vi, type Mock } from 'vitest';
import { GetPaymentsUseCase, type GetPaymentsInput } from './GetPaymentsUseCase';
import type { IPaymentRepository } from '../../domain/repositories/IPaymentRepository';
import { PaymentType, PayerType } from '../../domain/entities/Payment';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';

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

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

    output = {
      present: vi.fn(),
    };

    useCase = new GetPaymentsUseCase(
      paymentRepository as unknown as IPaymentRepository,
      output as unknown as UseCaseOutputPort<unknown>,
    );
  });

  it('retrieves payments and presents the 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,
    });
    expect(output.present).toHaveBeenCalledWith({ payments });
  });
});