package eu.jonahbauer.raytracing.scene.util;

import eu.jonahbauer.raytracing.math.BoundingBox;
import eu.jonahbauer.raytracing.math.Ray;
import eu.jonahbauer.raytracing.scene.Hittable;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;

public final class HittableList extends HittableCollection {
    private final @NotNull List<Hittable> objects;
    private final @NotNull Optional<BoundingBox> bbox;

    public HittableList(@NotNull List<? extends @NotNull Hittable> objects) {
        this.objects = List.copyOf(objects);
        this.bbox = getBoundingBox(this.objects);
    }

    public HittableList(@NotNull Hittable @NotNull... objects) {
        this(List.of(objects));
    }

    @Override
    public void hit(@NotNull Ray ray, @NotNull State state) {
        objects.forEach(object -> hit(state, ray, object));
    }

    @Override
    public @NotNull Optional<BoundingBox> getBoundingBox() {
        return bbox;
    }
}
