class ProductInventoryServiceImpl implements ProductInventoryService {
	
	
	@Autowired
	private PricingService pricingService;

	@Override
	public ProductInventory inventory(Product product) throws ServiceException {
		Validate.notNull(product.getAvailabilities());
		
		ProductAvailability availability = defaultAvailability(product.getAvailabilities());
		FinalPrice finalPrice = pricingService.calculateProductPrice(product);
		
		ProductInventory inventory = inventory(availability, finalPrice);
		inventory.setSku(product.getSku());
		return inventory;
	}

	@Override
	public ProductInventory inventory(ProductVariant variant) throws ServiceException {
		Validate.notNull(variant.getAvailabilities());
		Validate.notNull(variant.getProduct());
		
		ProductAvailability availability = null;
		if(!CollectionUtils.isEmpty(variant.getAvailabilities())) {
			availability = defaultAvailability(variant.getAvailabilities());
		} else {
			availability = defaultAvailability(variant.getProduct().getAvailabilities());
		}
		FinalPrice finalPrice = pricingService.calculateProductPrice(variant);
		
		if(finalPrice==null) {
			finalPrice = pricingService.calculateProductPrice(variant.getProduct());
		}
		
		ProductInventory inventory = inventory(availability, finalPrice);
		inventory.setSku(variant.getSku());
		return inventory;
	}
	
	private ProductAvailability defaultAvailability(Set<ProductAvailability> availabilities) {<FILL_FUNCTION_BODY>}
	
	private ProductInventory inventory(ProductAvailability availability, FinalPrice price) {
		ProductInventory inventory = new ProductInventory();
		inventory.setQuantity(availability.getProductQuantity());
		inventory.setPrice(price);
		
		return inventory;
	}

}

		
		ProductAvailability defaultAvailability = availabilities.iterator().next();
		
		for (ProductAvailability availability : availabilities) {
			if (!StringUtils.isEmpty(availability.getRegion())
					&& availability.getRegion().equals(Constants.ALL_REGIONS)) {// TODO REL 2.1 accept a region
				defaultAvailability = availability;
			}
		}
		
		return defaultAvailability;
		
	
<no_super_class>