import { type IAdminQueryRepository } from '../../domain/repositories/admin-query.repository';
import { GetDashboardStatsHandler } from '../queries/get-dashboard-stats/get-dashboard-stats.handler';
import { GetDashboardStatsQuery } from '../queries/get-dashboard-stats/get-dashboard-stats.query';

describe('GetDashboardStatsHandler', () => {
  let handler: GetDashboardStatsHandler;
  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 GetDashboardStatsHandler(mockAdminQueryRepo as any);
  });

  it('returns dashboard stats', async () => {
    const stats = {
      totalUsers: 150,
      totalListings: 500,
      activeListings: 200,
      pendingModerationCount: 15,
      totalAgents: 30,
      verifiedAgents: 20,
      totalTransactions: 50,
      newUsersLast30Days: 25,
      newListingsLast30Days: 40,
    };

    mockAdminQueryRepo.getDashboardStats.mockResolvedValue(stats);

    const result = await handler.execute(new GetDashboardStatsQuery());

    expect(result).toEqual(stats);
    expect(mockAdminQueryRepo.getDashboardStats).toHaveBeenCalledTimes(1);
  });
});
