// Generated by delombok at Tue Dec 16 19:35:38 UTC 2025
package net.md_5.bungee.log;

import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.regex.Pattern;
import net.md_5.bungee.api.ChatColor;
import org.jline.jansi.Ansi;
import org.jline.reader.LineReader;

public class ColouredWriter extends Handler {

    private static class ReplacementSpecification {
        private final Pattern pattern;
        private final String replacement;

        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        public ReplacementSpecification(final Pattern pattern, final String replacement) {
            this.pattern = pattern;
            this.replacement = replacement;
        }

        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        public Pattern getPattern() {
            return this.pattern;
        }

        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        public String getReplacement() {
            return this.replacement;
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        public boolean equals(final java.lang.Object o) {
            if (o == this) return true;
            if (!(o instanceof ColouredWriter.ReplacementSpecification)) return false;
            final ColouredWriter.ReplacementSpecification other = (ColouredWriter.ReplacementSpecification) o;
            if (!other.canEqual((java.lang.Object) this)) return false;
            final java.lang.Object this$pattern = this.getPattern();
            final java.lang.Object other$pattern = other.getPattern();
            if (this$pattern == null ? other$pattern != null : !this$pattern.equals(other$pattern)) return false;
            final java.lang.Object this$replacement = this.getReplacement();
            final java.lang.Object other$replacement = other.getReplacement();
            if (this$replacement == null ? other$replacement != null : !this$replacement.equals(other$replacement)) return false;
            return true;
        }

        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        protected boolean canEqual(final java.lang.Object other) {
            return other instanceof ColouredWriter.ReplacementSpecification;
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        public int hashCode() {
            final int PRIME = 59;
            int result = 1;
            final java.lang.Object $pattern = this.getPattern();
            result = result * PRIME + ($pattern == null ? 43 : $pattern.hashCode());
            final java.lang.Object $replacement = this.getReplacement();
            result = result * PRIME + ($replacement == null ? 43 : $replacement.hashCode());
            return result;
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("all")
        @lombok.Generated
        public java.lang.String toString() {
            return "ColouredWriter.ReplacementSpecification(pattern=" + this.getPattern() + ", replacement=" + this.getReplacement() + ")";
        }
    }

    private static ReplacementSpecification compile(ChatColor color, String ansi) {
        return new ReplacementSpecification(Pattern.compile("(?i)" + color.toString()), ansi);
    }

    private static final ReplacementSpecification[] REPLACEMENTS = new ReplacementSpecification[] {compile(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString()), compile(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString()), compile(ChatColor.DARK_GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString()), compile(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString()), compile(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString()), compile(ChatColor.DARK_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString()), compile(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString()), compile(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString()), compile(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString()), compile(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString()), compile(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString()), compile(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString()), compile(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString()), compile(ChatColor.LIGHT_PURPLE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString()), compile(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString()), compile(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString()), compile(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString()), compile(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString()), compile(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString()), compile(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString()), compile(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString()), compile(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString())};
    //
    private final LineReader console;

    public void print(String s) {
        for (ReplacementSpecification replacement : REPLACEMENTS) {
            s = replacement.pattern.matcher(s).replaceAll(replacement.replacement);
        }
        console.printAbove(s + Ansi.ansi().reset().toString());
    }

    @Override
    public void publish(LogRecord record) {
        if (isLoggable(record)) {
            print(getFormatter().format(record));
        }
    }

    @Override
    public void flush() {
    }

    @Override
    public void close() throws SecurityException {
    }

    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public ColouredWriter(final LineReader console) {
        this.console = console;
    }
}
