package net.minecraft.network.chat;

import java.util.Iterator;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.Unit;
import java.util.Optional;

public interface FormattedText {
    public static final Optional<Unit> STOP_ITERATION = Optional.<Unit>of(Unit.INSTANCE);
    public static final FormattedText EMPTY = new FormattedText() {
        @Override
        public <T> Optional<T> visit(final ContentConsumer<T> a) {
            return Optional.<T>empty();
        }
        
        @Override
        public <T> Optional<T> visit(final StyledContentConsumer<T> b, final Style nb) {
            return Optional.<T>empty();
        }
    };
    
     <T> Optional<T> visit(final ContentConsumer<T> a);
    
     <T> Optional<T> visit(final StyledContentConsumer<T> b, final Style nb);
    
    default FormattedText of(final String string) {
        return new FormattedText() {
            @Override
            public <T> Optional<T> visit(final ContentConsumer<T> a) {
                return a.accept(string);
            }
            
            @Override
            public <T> Optional<T> visit(final StyledContentConsumer<T> b, final Style nb) {
                return b.accept(nb, string);
            }
        };
    }
    
    default FormattedText of(final String string, final Style nb) {
        return new FormattedText() {
            @Override
            public <T> Optional<T> visit(final ContentConsumer<T> a) {
                return a.accept(string);
            }
            
            @Override
            public <T> Optional<T> visit(final StyledContentConsumer<T> b, final Style nb) {
                return b.accept(nb.applyTo(nb), string);
            }
        };
    }
    
    default FormattedText composite(final FormattedText... arr) {
        return composite(ImmutableList.<FormattedText>copyOf(arr));
    }
    
    default FormattedText composite(final List<FormattedText> list) {
        return new FormattedText() {
            @Override
            public <T> Optional<T> visit(final ContentConsumer<T> a) {
                for (final FormattedText mu4 : list) {
                    final Optional<T> optional5 = mu4.<T>visit(a);
                    if (optional5.isPresent()) {
                        return optional5;
                    }
                }
                return Optional.<T>empty();
            }
            
            @Override
            public <T> Optional<T> visit(final StyledContentConsumer<T> b, final Style nb) {
                for (final FormattedText mu5 : list) {
                    final Optional<T> optional6 = mu5.<T>visit(b, nb);
                    if (optional6.isPresent()) {
                        return optional6;
                    }
                }
                return Optional.<T>empty();
            }
        };
    }
    
    default String getString() {
        final StringBuilder stringBuilder2 = new StringBuilder();
        this.visit(string -> {
            stringBuilder2.append(string);
            return Optional.empty();
        });
        return stringBuilder2.toString();
    }
    
    public interface ContentConsumer<T> {
        Optional<T> accept(final String string);
    }
    
    public interface StyledContentConsumer<T> {
        Optional<T> accept(final Style nb, final String string);
    }
}
