import { describe, it, expect } from 'vitest';
import { KycApprovedEvent } from '../events/kyc-approved.event';
import { KycRejectedEvent } from '../events/kyc-rejected.event';
import { ListingApprovedEvent } from '../events/listing-approved.event';
import { ListingRejectedEvent } from '../events/listing-rejected.event';
import { SubscriptionAdjustedEvent } from '../events/subscription-adjusted.event';
import { UserBannedEvent } from '../events/user-banned.event';
import { UserUnbannedEvent } from '../events/user-unbanned.event';

describe('Admin Domain Events', () => {
  describe('ListingApprovedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new ListingApprovedEvent('listing-1', 'admin-1', 'Looks good');

      expect(event.eventName).toBe('listing.approved_by_admin');
      expect(event.aggregateId).toBe('listing-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.moderationNotes).toBe('Looks good');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event without moderation notes', () => {
      const event = new ListingApprovedEvent('listing-2', 'admin-1');

      expect(event.moderationNotes).toBeUndefined();
    });
  });

  describe('ListingRejectedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new ListingRejectedEvent('listing-1', 'admin-1', 'Ảnh không hợp lệ');

      expect(event.eventName).toBe('listing.rejected_by_admin');
      expect(event.aggregateId).toBe('listing-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.reason).toBe('Ảnh không hợp lệ');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('UserBannedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new UserBannedEvent('user-1', 'admin-1', 'Vi phạm chính sách');

      expect(event.eventName).toBe('user.banned');
      expect(event.aggregateId).toBe('user-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.reason).toBe('Vi phạm chính sách');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

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

      expect(event.eventName).toBe('user.unbanned');
      expect(event.aggregateId).toBe('user-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('SubscriptionAdjustedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new SubscriptionAdjustedEvent(
        'sub-1',
        'admin-1',
        'plan-premium',
        'Nâng cấp hỗ trợ đặc biệt',
      );

      expect(event.eventName).toBe('subscription.adjusted_by_admin');
      expect(event.aggregateId).toBe('sub-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.newPlanId).toBe('plan-premium');
      expect(event.reason).toBe('Nâng cấp hỗ trợ đặc biệt');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });

  describe('KycApprovedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new KycApprovedEvent('user-1', 'admin-1', 'Hồ sơ đầy đủ');

      expect(event.eventName).toBe('kyc.approved');
      expect(event.aggregateId).toBe('user-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.comments).toBe('Hồ sơ đầy đủ');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });

    it('creates event without comments', () => {
      const event = new KycApprovedEvent('user-2', 'admin-1');

      expect(event.comments).toBeUndefined();
    });
  });

  describe('KycRejectedEvent', () => {
    it('creates event with correct properties', () => {
      const event = new KycRejectedEvent('user-1', 'admin-1', 'CMND mờ không đọc được');

      expect(event.eventName).toBe('kyc.rejected');
      expect(event.aggregateId).toBe('user-1');
      expect(event.adminId).toBe('admin-1');
      expect(event.reason).toBe('CMND mờ không đọc được');
      expect(event.occurredAt).toBeInstanceOf(Date);
    });
  });
});
