import { describe, it, expect } from 'vitest';
import { SubscriptionCancelledEvent } from '../events/subscription-cancelled.event';
import { SubscriptionCreatedEvent } from '../events/subscription-created.event';
import { SubscriptionExpiredEvent } from '../events/subscription-expired.event';
import { SubscriptionRenewedEvent } from '../events/subscription-renewed.event';
import { SubscriptionUpgradedEvent } from '../events/subscription-upgraded.event';

describe('Subscription Domain Events', () => {
  describe('SubscriptionCreatedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new SubscriptionCreatedEvent('sub-1', 'user-1', 'BASIC');

      expect(event.eventName).toBe('subscription.created');
      expect(event.aggregateId).toBe('sub-1');
      expect(event.userId).toBe('user-1');
      expect(event.planTier).toBe('BASIC');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event for PREMIUM tier', () => {
      const event = new SubscriptionCreatedEvent('sub-2', 'user-2', 'PREMIUM');
      expect(event.planTier).toBe('PREMIUM');
    });
  });

  describe('SubscriptionUpgradedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new SubscriptionUpgradedEvent('sub-1', 'user-1', 'BASIC', 'PREMIUM');

      expect(event.eventName).toBe('subscription.upgraded');
      expect(event.aggregateId).toBe('sub-1');
      expect(event.userId).toBe('user-1');
      expect(event.fromTier).toBe('BASIC');
      expect(event.toTier).toBe('PREMIUM');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('SubscriptionCancelledEvent', () => {
    it('creates event with correct properties', () => {
      const event = new SubscriptionCancelledEvent('sub-1', 'user-1', 'PREMIUM');

      expect(event.eventName).toBe('subscription.cancelled');
      expect(event.aggregateId).toBe('sub-1');
      expect(event.userId).toBe('user-1');
      expect(event.planTier).toBe('PREMIUM');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('SubscriptionExpiredEvent', () => {
    it('creates event with correct properties', () => {
      const event = new SubscriptionExpiredEvent('sub-1', 'user-1', 'AGENT_PRO');

      expect(event.eventName).toBe('subscription.expired');
      expect(event.aggregateId).toBe('sub-1');
      expect(event.userId).toBe('user-1');
      expect(event.planTier).toBe('AGENT_PRO');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('SubscriptionRenewedEvent', () => {
    it('creates event with correct properties', () => {
      const start = new Date('2026-02-01');
      const end = new Date('2026-03-01');
      const event = new SubscriptionRenewedEvent('sub-1', 'user-1', 'PREMIUM', start, end);

      expect(event.eventName).toBe('subscription.renewed');
      expect(event.aggregateId).toBe('sub-1');
      expect(event.userId).toBe('user-1');
      expect(event.planTier).toBe('PREMIUM');
      expect(event.newPeriodStart).toEqual(start);
      expect(event.newPeriodEnd).toEqual(end);
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });
});
