import { describe, it, expect } from 'vitest';
import { PaymentCompletedEvent } from '../events/payment-completed.event';
import { PaymentCreatedEvent } from '../events/payment-created.event';
import { PaymentFailedEvent } from '../events/payment-failed.event';
import { PaymentRefundedEvent } from '../events/payment-refunded.event';

describe('Payment Domain Events', () => {
  describe('PaymentCreatedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new PaymentCreatedEvent(
        'payment-1',
        'user-1',
        'VNPAY',
        'SUBSCRIPTION',
        500_000n,
      );

      expect(event.eventName).toBe('payment.created');
      expect(event.aggregateId).toBe('payment-1');
      expect(event.userId).toBe('user-1');
      expect(event.provider).toBe('VNPAY');
      expect(event.type).toBe('SUBSCRIPTION');
      expect(event.amountVND).toBe(500_000n);
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event for LISTING_FEE type', () => {
      const event = new PaymentCreatedEvent(
        'payment-2',
        'user-2',
        'VNPAY',
        'LISTING_FEE',
        100_000n,
      );
      expect(event.type).toBe('LISTING_FEE');
    });
  });

  describe('PaymentCompletedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new PaymentCompletedEvent('payment-1', 'user-1', 'VNPAY', 500_000n);

      expect(event.eventName).toBe('payment.completed');
      expect(event.aggregateId).toBe('payment-1');
      expect(event.userId).toBe('user-1');
      expect(event.provider).toBe('VNPAY');
      expect(event.amountVND).toBe(500_000n);
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('PaymentFailedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new PaymentFailedEvent('payment-1', 'user-1', 'VNPAY');

      expect(event.eventName).toBe('payment.failed');
      expect(event.aggregateId).toBe('payment-1');
      expect(event.userId).toBe('user-1');
      expect(event.provider).toBe('VNPAY');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('PaymentRefundedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new PaymentRefundedEvent('payment-1', 'user-1', 'VNPAY', 500_000n);

      expect(event.eventName).toBe('payment.refunded');
      expect(event.aggregateId).toBe('payment-1');
      expect(event.userId).toBe('user-1');
      expect(event.provider).toBe('VNPAY');
      expect(event.amountVND).toBe(500_000n);
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });
});
