import { Injectable } from '@angular/core';
import { Hero } from './models/hero';
import { HEROES } from './mocks/mock-heroes';
import { Observable, of } from 'rxjs';
import { MessageService } from './message.service';

@Injectable({
  providedIn: 'root'
})
export class HeroService {

  constructor(private messageService: MessageService) { }

  getHeroes(): Observable<Hero[]> {
    this.messageService.add('HeroService: ไปเอาข้อมูล heroes มา');
    return of(HEROES);
  }

  getHero(id: number): Observable<Hero> {
    this.messageService.add(`HeroService: ไปเอาข้อมูล hero id ${id} มา`);
    return of(HEROES.find(hero => hero.id === id));
  }
}
