use super::ExampleScene;
use crate::basic_scene::BasicScene;
use ray_tracing_core::prelude::*;
use std::cell::{Cell, OnceCell};

pub struct SphereScene<M> {
    scene: OnceCell<BasicScene<M>>,
    material: Cell<Option<M>>,
}

impl<M> SphereScene<M> {
    pub fn new(material: M) -> Self {
        Self {
            scene: OnceCell::new(),
            material: Cell::new(Some(material)),
        }
    }
}

impl<R: Rng + 'static, M: Material<R> + Clone + 'static> ExampleScene<R> for SphereScene<M> {
    fn get_scene(&self) -> Box<dyn ray_tracing_core::scene::Scene<R> + Sync> {
        let s = self
            .scene
            .get_or_init(|| BasicScene::new(self.material.take().unwrap()));

        Box::new(s.clone())
    }

    fn get_camera_pos(&self) -> Pos3 {
        Pos3::new(5.0, 1.0, 0.0)
    }

    fn get_camera_look_at(&self) -> Pos3 {
        Pos3::new(0.0, 0.0, 0.0)
    }

    fn get_camera_up(&self) -> Dir3 {
        Dir3::up()
    }

    fn get_horizontal_fov(&self) -> Float {
        Float::to_radians(90.0)
    }
}
