use crate::Arena;
use crate::core::sampler::CreateSampler;
use crate::utils::{FileLoc, ParameterDictionary};
use anyhow::Result;
use shared::core::geometry::Point2i;
use shared::core::options::get_options;
use shared::core::sampler::IndependentSampler;

impl CreateSampler for IndependentSampler {
    fn create(
        params: &ParameterDictionary,
        _full_res: Point2i,
        _loc: &FileLoc,
        arena: &mut Arena,
    ) -> Result<Self> {
        let options = get_options();
        let nsamp = options
            .quick_render
            .then_some(1)
            .or(options.pixel_samples)
            .unwrap_or_else(|| params.get_one_int("pixelsamples", 16));
        let seed = params.get_one_int("seed", options.seed);
        let sampler = Self::new(nsamp, seed as u64);
        arena.alloc(sampler);
        Ok(sampler)
    }
}
