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 bfn) {
        this.transitions = Lists.newArrayList();
        this.schedule = bfn;
    }
    
    public ScheduleBuilder changeActivityAt(final int integer, final Activity bfl) {
        this.transitions.add(new ActivityTransition(integer, bfl));
        return this;
    }
    
    public Schedule build() {
        this.transitions.stream().map(ActivityTransition::getActivity).collect(Collectors.toSet()).forEach(this.schedule::ensureTimelineExistsFor);
        final Activity bfl3;
        this.transitions.forEach(a -> {
            bfl3 = a.getActivity();
            this.schedule.getAllTimelinesExceptFor(bfl3).forEach(bfp -> bfp.addKeyframe(a.getTime(), 0.0f));
            this.schedule.getTimelineFor(bfl3).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 bfl) {
            this.time = integer;
            this.activity = bfl;
        }
        
        public int getTime() {
            return this.time;
        }
        
        public Activity getActivity() {
            return this.activity;
        }
    }
}
