use serde::{Deserialize, Serialize};

use crate::ecs::graphics::resources::{ColorGrading, DepthOfField, Fog, VertexSnap};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct SceneSettings {
    pub gravity: [f32; 3],
    pub physics_timestep: f32,
    pub physics_max_substeps: u32,
    pub ambient_light: [f32; 4],
    pub clear_color: [f32; 4],
    pub fog: Option<Fog>,
    pub bloom_enabled: bool,
    pub bloom_intensity: f32,
    pub bloom_threshold: f32,
    pub color_grading: ColorGrading,
    pub depth_of_field: DepthOfField,
    pub ssao_enabled: bool,
    pub ssao_radius: f32,
    pub ssao_bias: f32,
    pub ssao_intensity: f32,
    pub ssao_sample_count: u32,
    pub ssgi_enabled: bool,
    pub ssgi_radius: f32,
    pub ssgi_intensity: f32,
    pub ssgi_max_steps: u32,
    pub ssr_enabled: bool,
    pub ssr_max_steps: u32,
    pub ssr_thickness: f32,
    pub ssr_max_distance: f32,
    pub ssr_stride: f32,
    pub ssr_fade_start: f32,
    pub ssr_fade_end: f32,
    pub ssr_intensity: f32,
    pub vertex_snap: Option<VertexSnap>,
    pub affine_texture_mapping: bool,
    pub day_night_hour: Option<f32>,
}

impl Default for SceneSettings {
    fn default() -> Self {
        Self {
            gravity: [0.0, -9.81, 0.0],
            physics_timestep: 1.0 / 60.0,
            physics_max_substeps: 4,
            ambient_light: [0.1, 0.1, 0.1, 1.0],
            clear_color: [0.0, 0.0, 0.0, 1.0],
            fog: None,
            bloom_enabled: true,
            bloom_intensity: 0.5,
            bloom_threshold: 1.0,
            color_grading: ColorGrading::default(),
            depth_of_field: DepthOfField::default(),
            ssao_enabled: false,
            ssao_radius: 0.5,
            ssao_bias: 0.025,
            ssao_intensity: 1.0,
            ssao_sample_count: 64,
            ssgi_enabled: false,
            ssgi_radius: 2.0,
            ssgi_intensity: 1.0,
            ssgi_max_steps: 16,
            ssr_enabled: false,
            ssr_max_steps: 64,
            ssr_thickness: 0.3,
            ssr_max_distance: 50.0,
            ssr_stride: 1.0,
            ssr_fade_start: 0.8,
            ssr_fade_end: 1.0,
            ssr_intensity: 1.0,
            vertex_snap: None,
            affine_texture_mapping: false,
            day_night_hour: None,
        }
    }
}
