import { Injectable } from "@angular/core";
import { Observable, map } from "rxjs";
import { HostingInfoModel } from "../models/hosting-info";
import { hostingInfo } from "../data/hosting-info";

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

  hostingInfoData = new Observable<HostingInfoModel[]>((subscriber) => {
    subscriber.next(hostingInfo);
  });

  // Get all hosting info
  getAllHostingInfo(): Observable<HostingInfoModel[]> {
    return this.hostingInfoData;
  }

  // Get a hosting info based on id
  getHostingInfoById(id: number): Observable<HostingInfoModel> {
    return this.hostingInfoData.pipe(
      map((hostingInfo) =>
        hostingInfo.find((hostingInfo) => hostingInfo.id === id)
      )
    );
  }
}
