class FreeResourcesLimitValidator {

  public void check(FreeResourcesLimitDto freeResourcesLimit) throws BadRequestException {
    if (freeResourcesLimit == null) {
      throw new BadRequestException("Missed free resources limit description.");
    }
    if (freeResourcesLimit.getAccountId() == null) {
      throw new BadRequestException("Missed account id.");
    }

    Set<String> resourcesToSet = new HashSet<>();
    for (ResourceDto resource : freeResourcesLimit.getResources()) {
      if (!resourcesToSet.add(resource.getType())) {
        throw new BadRequestException(
            format(
                "Free resources limit should contain only one resources with type '%s'.",
                resource.getType()));
      }
      resourceValidator.validate(resource);
    }
  }

  @Inject public  FreeResourcesLimitValidator(ResourceValidator resourceValidator);

}