class PlatformChecker {

  static void checkManifestPlatform(
      BuildContext buildContext, ContainerConfigurationTemplate containerConfig) {
    EventHandlers eventHandlers = buildContext.getEventHandlers();
    String baseImageName =
        buildContext.getBaseImageConfiguration().getTarPath().isPresent()
            ? buildContext.getBaseImageConfiguration().getTarPath().get().toString()
            : buildContext.getBaseImageConfiguration().getImage().toString();

    Set<Platform> platforms = buildContext.getContainerConfiguration().getPlatforms();
    Verify.verify(!platforms.isEmpty());

    if (platforms.size() != 1) {
      eventHandlers.dispatch(
          LogEvent.warn(
              "platforms configured, but '" + baseImageName + "' is not a manifest list"));
    } else {
      Platform platform = platforms.iterator().next();
      if (!platform.getArchitecture().equals(containerConfig.getArchitecture())
          || !platform.getOs().equals(containerConfig.getOs())) {

        // Unfortunately, "platforms" has amd64/linux by default even if the user didn't explicitly
        // configure it. Skip reporting to suppress false alarm.
        if (!(platform.getArchitecture().equals("amd64") && platform.getOs().equals("linux"))) {
          String warning =
              "the configured platform (%s/%s) doesn't match the platform (%s/%s) of the base "
                  + "image (%s)";
          eventHandlers.dispatch(
              LogEvent.warn(
                  String.format(
                      warning,
                      platform.getArchitecture(),
                      platform.getOs(),
                      containerConfig.getArchitecture(),
                      containerConfig.getOs(),
                      baseImageName)));
        }
      }
    }
  }

}