package com.nincraft.ninbot.container;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
public class Event {
    private int id;
    private String name;
    private String authorName;
    private String gameName;
    private String description;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private int hidden;

    public String buildChannelMessage(String roleId, int minutesBeforeStart) {
        if (minutesBeforeStart > 0) {
            String timezoneConvert = getTimezoneConvert(startTime);
            String timezoneUrl = formatTime(timezoneConvert);
            return String.format("<@&%s>, event %s created by %s is starting in %s minutes - click here for your timezone %s", roleId, name, authorName, minutesBeforeStart, timezoneUrl);
        } else {
            if (StringUtils.isNotBlank(endTime.toString())) {
                String timezoneConvert = getTimezoneConvert(endTime);
                String timezoneUrl = formatTime(timezoneConvert);
                return String.format("<@&%s>, event %s created by %s is starting now and will end at %s - click here for your timezone %s", roleId, name, authorName,
                        endTime, timezoneUrl);
            } else {
                return String.format("<@&%s>, event %s created by %s is starting now", roleId, name, authorName);
            }
        }
    }

    private String formatTime(String timezoneConvert) {
        return String.format("http://www.thetimezoneconverter.com/?t=%s&tz=Chicago", timezoneConvert);
    }

    private String getTimezoneConvert(LocalDateTime time) {
        return time.format(DateTimeFormatter.ofPattern("hh:mm a")).replaceAll(" ", "%20");
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Name: ");
        stringBuilder.append(name);
        if (StringUtils.isNotBlank(description)) {
            stringBuilder.append("\n");
            stringBuilder.append(description);

        }
        stringBuilder.append("\nCreated by: ");
        stringBuilder.append(authorName);
        stringBuilder.append("\nGame: ");
        stringBuilder.append(StringUtils.capitalize(gameName));
        stringBuilder.append("\nStart Time: ");
        stringBuilder.append(startTime);
        if (StringUtils.isNotBlank(endTime.toString())) {
            stringBuilder.append("\nEnd Time: ");
            stringBuilder.append(endTime);
        }
        return stringBuilder.toString();
    }
}

@@ -134,51 +134,8 @@
 ime;
-%0Aimport java.time.format.DateTimeFormatter;
 %0A%0A@D
@@ -514,138 +514,8 @@
 ) %7B%0A
-            String timezoneConvert = getTimezoneConvert(startTime);%0A            String timezoneUrl = formatTime(timezoneConvert);%0A
     
@@ -595,17 +595,17 @@
 in %25
-s
+d
  minutes
  - c
@@ -604,42 +604,8 @@
 utes
- - click here for your timezone %25s
 %22, r
@@ -647,29 +647,16 @@
 oreStart
-, timezoneUrl
 );%0A     
@@ -733,144 +733,8 @@
 ) %7B%0A
-                String timezoneConvert = getTimezoneConvert(endTime);%0A                String timezoneUrl = formatTime(timezoneConvert);%0A
     
@@ -834,42 +834,8 @@
  at 
-%25s - click here for your timezone 
 %25s%22,
@@ -896,21 +896,8 @@
 Time
-, timezoneUrl
 );%0A 
@@ -1065,332 +1065,8 @@
  %7D%0A%0A
-    private String formatTime(String timezoneConvert) %7B%0A        return String.format(%22http://www.thetimezoneconverter.com/?t=%25s&tz=Chicago%22, timezoneConvert);%0A    %7D%0A%0A    private String getTimezoneConvert(LocalDateTime time) %7B%0A        return time.format(DateTimeFormatter.ofPattern(%22hh:mm a%22)).replaceAll(%22 %22, %22%2520%22);%0A    %7D%0A%0A
     

Fix parse error