import { Injectable } from "@angular/core";
import { Observable, map } from "rxjs";
import { ServerInfoModel } from "../models/server-info";
import { serverInfo } from "../data/server-info";

@Injectable({
  providedIn: "root",
})
export class ServerInfoService {
  constructor() {}

  serverInfoData = new Observable<ServerInfoModel[]>((subscriber) => {
    subscriber.next(serverInfo);
  });

  // Get all server info
  getAllServerInfo(): Observable<ServerInfoModel[]> {
    return this.serverInfoData;
  }

  // Get a server info based on id
  getServerInfoById(id: number): Observable<ServerInfoModel> {
    return this.serverInfoData.pipe(
      map((serverInfo) =>
        serverInfo.find((serverInfo) => serverInfo.id === id)
      )
    );
  }
}
