package net.minecraft.world.entity.schedule;

import java.util.function.Consumer;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import java.util.Set;
import com.google.common.collect.Lists;
import java.util.List;

public class ScheduleBuilder {
    private final Schedule schedule;
    private final List<ActivityTransition> transitions;
    
    public ScheduleBuilder(final Schedule azt) {
        this.transitions = Lists.newArrayList();
        this.schedule = azt;
    }
    
    public ScheduleBuilder changeActivityAt(final int integer, final Activity azr) {
        this.transitions.add(new ActivityTransition(integer, azr));
        return this;
    }
    
    public Schedule build() {
        this.transitions.stream().map(ActivityTransition::getActivity).collect(Collectors.toSet()).forEach(this.schedule::ensureTimelineExistsFor);
        final Activity azr3;
        this.transitions.forEach(a -> {
            azr3 = a.getActivity();
            this.schedule.getAllTimelinesExceptFor(azr3).forEach(azv -> azv.addKeyframe(a.getTime(), 0.0f));
            this.schedule.getTimelineFor(azr3).addKeyframe(a.getTime(), 1.0f);
            return;
        });
        return this.schedule;
    }
    
    static class ActivityTransition {
        private final int time;
        private final Activity activity;
        
        public ActivityTransition(final int integer, final Activity azr) {
            this.time = integer;
            this.activity = azr;
        }
        
        public int getTime() {
            return this.time;
        }
        
        public Activity getActivity() {
            return this.activity;
        }
    }
}
