import { Reservation,Chantier,User, Ressources } from "./class";

export function getNbItemReservation(reservations:Reservation[]):number{
  var res = 0;
  reservations.forEach(reserv => {
    res += reserv.quantity;
  });
  return res;
}


export function getReservationOfRessource(ressource:Ressources, allReservations:Reservation[]):Reservation[]{
  const res:Reservation[] = [];
  allReservations.forEach(reserv => {
    if(reserv.ressource.name===ressource.name){
      res.push(reserv);
    }
  });
  return res;
}


export function getNbUseRessources(ressource:Ressources, allReservations:Reservation[]):number{
  var res:number = 0;
  getReservationOfRessource(ressource,allReservations).forEach(reserv => {
    if(reserv.chantier.etat==="En cours"){
      res+=reserv.quantity;
    }
  })
  return res;
}