package wtf.opal.client.notification;

import java.util.ArrayList;
import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public final class NotificationManager {
   private final List<Notification> notifications = new ArrayList<>();

   public List<Notification> getNotifications() {
      return this.notifications;
   }

   public NotificationManager.NotificationBuilder builder(NotificationType type) {
      return new NotificationManager.NotificationBuilder(this, type);
   }

   private Notification publish(Notification notification) {
      System.out.println(notification.getTitle() + ": " + notification.getDescription());
      this.notifications.add(notification);
      return notification;
   }

   public void remove(Notification notification) {
      this.notifications.remove(notification);
   }

   @Environment(EnvType.CLIENT)
   public static class NotificationBuilder {
      private final NotificationManager dispatcher;
      private final NotificationType type;
      private String title;
      private String description;
      private int duration;

      private NotificationBuilder(NotificationManager dispatcher, NotificationType type) {
         this.dispatcher = dispatcher;
         this.type = type;
         this.title = "Notification";
         this.duration = 2000;
      }

      public NotificationManager.NotificationBuilder title(String title) {
         this.title = title;
         return this;
      }

      public NotificationManager.NotificationBuilder description(String description) {
         this.description = description;
         return this;
      }

      public NotificationManager.NotificationBuilder duration(int duration) {
         this.duration = duration;
         return this;
      }

      public Notification buildAndPublish() {
         return this.dispatcher.publish(new Notification(this.type, this.title, this.description, this.duration));
      }
}
}
