import { Pipe, PipeTransform } from '@angular/core';
import { AvailabilityByBranchDTO } from 'apps/domain/availability/src/lib/defs/availability-by-branch-dto.model';

@Pipe({
  name: 'inStock',
})
export class InStockPipe implements PipeTransform {
  transform(branchId: number, inStock: AvailabilityByBranchDTO[]): number {
    const stock = inStock?.find((info) => info.branchId === branchId)?.inStock || 0;
    return stock > 0 ? stock : 0;
  }
}
