import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Monster } from './monster.entity';

@Injectable()
export class MonsterService {
  constructor(
    @InjectRepository(Monster)
    private readonly monsterRepository: Repository<Monster>,
  ) {}

  findAll(): Promise<Monster[]> {
    return this.monsterRepository.find({ order: { minLevel: 'ASC' } });
  }

  async findOne(id: string): Promise<Monster> {
    const monster = await this.monsterRepository.findOne({ where: { id } });
    if (!monster) throw new NotFoundException(`Monstre introuvable`);
    return monster;
  }
}
