import { Controller, Get, Param } from '@nestjs/common';
import { UserRepo } from '../../repos/user.repo';
import { UserMapper } from '../../mappers/user.mapper';

@Controller('users')
export class GetUserUseCase {
  constructor(private userRepo: UserRepo) {}

  @Get(':id')
  async execute(
    @Param('id') id: string,
  ) {
    const user = await this.userRepo.findById(id);

    if (!user) {
      throw new Error('User not found');
    }

    return UserMapper.toDTO(user);
  }
}
