use crate::Float;
use crate::core::geometry::{Bounds2f, Bounds2i, Point2f, Point2i};
use core::ops::Deref;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RenderingCoordinateSystem {
    Camera,
    CameraWorld,
    World,
}

#[derive(Debug, Clone)]
pub struct BasicPBRTOptions {
    pub seed: i32,
    pub quiet: bool,
    pub disable_pixel_jitter: bool,
    pub disable_wavelength_jitter: bool,
    pub disable_texture_filtering: bool,
    pub force_diffuse: bool,
    pub use_gpu: bool,
    pub wavefront: bool,
    pub interactive: bool,
    pub fullscreen: bool,
    pub rendering_space: RenderingCoordinateSystem,
}

impl Default for BasicPBRTOptions {
    fn default() -> Self {
        Self {
            seed: 0,
            quiet: false,
            disable_pixel_jitter: false,
            disable_wavelength_jitter: false,
            disable_texture_filtering: false,
            force_diffuse: false,
            use_gpu: false,
            wavefront: false,
            interactive: false,
            fullscreen: false,
            rendering_space: RenderingCoordinateSystem::CameraWorld,
        }
    }
}

#[derive(Debug, Clone)]
pub struct PBRTOptions {
    pub basic: BasicPBRTOptions,

    pub n_threads: usize,
    pub log_level: &'static str,
    pub write_partial_images: bool,
    pub image_file: &'static str,
    pub pixel_samples: Option<i32>,
    pub gpu_device: Option<u32>,
    pub mse_reference_image: Option<&'static str>,
    pub mse_reference_output: Option<&'static str>,
    pub debug_start: Option<(Point2i, i32)>,
    pub quick_render: bool,
    pub upgrade: bool,
    pub display_server: &'static str,
    pub crop_window: Option<Bounds2f>,
    pub pixel_bounds: Option<Bounds2i>,
    pub pixel_material: Option<Point2i>,
    pub displacement_edge_scale: Float,
}

impl Default for PBRTOptions {
    fn default() -> Self {
        Self {
            basic: BasicPBRTOptions::default(),
            n_threads: 0,
            log_level: "info",
            write_partial_images: false,
            pixel_samples: None,
            gpu_device: None,
            quick_render: false,
            upgrade: false,
            image_file: "output.exr",
            mse_reference_image: None,
            mse_reference_output: None,
            debug_start: Some((Point2i::default(), 0)),
            display_server: "",
            crop_window: None,
            pixel_bounds: None,
            pixel_material: None,
            displacement_edge_scale: 1.,
        }
    }
}

impl Deref for PBRTOptions {
    type Target = BasicPBRTOptions;

    fn deref(&self) -> &Self::Target {
        &self.basic
    }
}
