use derive_builder::Builder;

use crate::tuples::{Color, Tuple};

#[derive(Builder, Clone, Debug, Default, PartialEq)]
#[builder(default)]
pub struct PointLight {
    pub position: Tuple,
    #[builder(setter(into))]
    pub intensity: Color,
}

impl PointLight {
    /// Creates a new `PositionLight` at the given `position` and with the given
    /// `intensity`.
    pub fn new<C>(position: Tuple, intensity: C) -> PointLight
    where
        C: Into<Color>,
    {
        PointLight {
            position,
            intensity: intensity.into(),
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::{lights::PointLight, tuples::point, WHITE};

    #[test]
    fn new() {
        let intensity = WHITE;
        let position = point(0., 0., 0.);
        let light = PointLight::new(position, intensity);
        assert_eq!(light.position, position);
        assert_eq!(light.intensity, intensity);
    }
}
