import { Injectable } from "@angular/core";
import { Observable, map } from "rxjs";
import { PaymentModel } from "../models/payment";
import { payment } from "../data/payment";

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

  paymentData = new Observable<PaymentModel[]>((subscriber) => {
    subscriber.next(payment);
  });

  // Get all payments
  getAllPayments(): Observable<PaymentModel[]> {
    return this.paymentData;
  }

  // Get a payment based on id
  getPaymentById(companyId: number): Observable<PaymentModel[]> {
    return this.paymentData.pipe(
      map((payment) => payment.filter((payment) => payment.companyId === companyId))
    );
  }
}
