import { type IAdminQueryRepository } from '../../domain/repositories/admin-query.repository';
import { GetModerationQueueHandler } from '../queries/get-moderation-queue/get-moderation-queue.handler';
import { GetModerationQueueQuery } from '../queries/get-moderation-queue/get-moderation-queue.query';

describe('GetModerationQueueHandler', () => {
  let handler: GetModerationQueueHandler;
  let mockAdminQueryRepo: { [K in keyof IAdminQueryRepository]: ReturnType<typeof vi.fn> };

  beforeEach(() => {
    mockAdminQueryRepo = {
      getModerationQueue: vi.fn(),
      getDashboardStats: vi.fn(),
      getRevenueStats: vi.fn(),
      getUsers: vi.fn(),
    };

    handler = new GetModerationQueueHandler(mockAdminQueryRepo as any);
  });

  it('returns moderation queue with pagination', async () => {
    const queueResult = {
      data: [
        {
          listingId: 'listing-1',
          propertyTitle: 'Căn hộ 2PN quận 7',
          propertyType: 'APARTMENT',
          transactionType: 'SALE',
          priceVND: 3_000_000_000n,
          sellerName: 'Nguyễn Văn A',
          sellerId: 'seller-1',
          moderationScore: null,
          createdAt: new Date(),
        },
      ],
      total: 1,
      page: 1,
      limit: 20,
      totalPages: 1,
    };

    mockAdminQueryRepo.getModerationQueue.mockResolvedValue(queueResult);

    const result = await handler.execute(new GetModerationQueueQuery(1, 20));

    expect(result.data).toHaveLength(1);
    expect(result.total).toBe(1);
    expect(mockAdminQueryRepo.getModerationQueue).toHaveBeenCalledWith(1, 20);
  });
});
