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

describe('CreatePaymentUseCase', () => {
  let paymentRepository: {
    create: Mock;
  };
  let useCase: CreatePaymentUseCase;

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

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

  it('creates a payment and returns result', async () => {
    const input: CreatePaymentInput = {
      type: PaymentType.SPONSORSHIP,
      amount: 100,
      payerId: 'payer-1',
      payerType: PayerType.SPONSOR,
      leagueId: 'league-1',
      seasonId: 'season-1',
    };

    const createdPayment = {
      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: PaymentStatus.PENDING,
      createdAt: new Date(),
    };

    paymentRepository.create.mockResolvedValue(createdPayment);

    const result = await useCase.execute(input);

    expect(result.isOk()).toBe(true);
    expect(paymentRepository.create).toHaveBeenCalled();
    
    if (result.isOk()) {
      expect(result.value.payment).toEqual(createdPayment);
    }
  });
});