import { type UserListResult } from '../../domain/repositories/admin-query.repository';
import { GetUsersHandler } from '../queries/get-users/get-users.handler';
import { GetUsersQuery } from '../queries/get-users/get-users.query';

describe('GetUsersHandler', () => {
  let handler: GetUsersHandler;
  let mockRepo: { getUsers: ReturnType<typeof vi.fn> };

  beforeEach(() => {
    mockRepo = {
      getUsers: vi.fn(),
    };
    handler = new GetUsersHandler(mockRepo as any);
  });

  it('returns paginated user list', async () => {
    const expected: UserListResult = {
      data: [
        {
          id: 'u1',
          email: 'test@test.com',
          phone: '0901234567',
          fullName: 'Test',
          role: 'BUYER',
          kycStatus: 'NONE',
          isActive: true,
          createdAt: new Date(),
        },
      ],
      total: 1,
      page: 1,
      limit: 20,
      totalPages: 1,
    };
    mockRepo.getUsers.mockResolvedValue(expected);

    const query = new GetUsersQuery(1, 20, 'BUYER', true, 'test');
    const result = await handler.execute(query);

    expect(result).toEqual(expected);
    expect(mockRepo.getUsers).toHaveBeenCalledWith({
      page: 1,
      limit: 20,
      role: 'BUYER',
      isActive: true,
      search: 'test',
    });
  });
});
