class WelcomeMsgUtils {

  public static void displayWelcomeMessage(
      final int consoleWidth,
      final PrintWriter writer
  ) {
    final String[] lines = {
        "",
        "===========================================",
        "=        _  __ _____  ____  _             =",
        "=       | |/ // ____|/ __ \\| |            =",
        "=       | ' /| (___ | |  | | |            =",
        "=       |  <  \\___ \\| |  | | |            =",
        "=       | . \\ ____) | |__| | |____        =",
        "=       |_|\\_\\_____/ \\___\\_\\______|       =",
        "=                                         =",
        "=  Streaming SQL Engine for Apache Kafka® =",
        "==========================================="
    };

    final String copyrightMsg = "Copyright 2017 Confluent Inc.";

    final Integer logoWidth = Arrays.stream(lines)
        .map(String::length)
        .reduce(0, Math::max);

    // Don't want to display the logo if it'll just end up getting wrapped and looking hideous
    if (consoleWidth < logoWidth) {
      writer.println("KSQL, " + copyrightMsg);
    } else {
      final int paddingChars = (consoleWidth - logoWidth) / 2;
      final String leftPadding = IntStream.range(0, paddingChars)
          .mapToObj(idx -> " ")
          .collect(Collectors.joining());

      Arrays.stream(lines)
          .forEach(line -> writer.println(leftPadding + line));

      writer.println();
      writer.println(copyrightMsg);
    }

    writer.println();
    writer.flush();
  }

  private  WelcomeMsgUtils();

}