use crate::{
	ray::Ray,
	vec3::{Color, Vec3},
};

use super::Material;

#[derive(Debug, Clone, Copy)]
pub struct Lambertian {
	albedo: Color,
}

impl Lambertian {
	pub const fn new(albedo: Color) -> Self {
		Self { albedo }
	}
}

impl Material for Lambertian {
	fn scatter(
		&self,
		_r_in: &crate::ray::Ray,
		hit_record: &crate::hittable::HitRecord,
	) -> Option<(Color, Ray)> {
		let mut scatter_direction = hit_record.normal + Vec3::random_unit_vector();

		if scatter_direction.near_zero() {
			scatter_direction = hit_record.normal;
		}

		Some((self.albedo, Ray::new(hit_record.p, scatter_direction)))
	}
}
