//! Configuration primitives.

use winit::{dpi::PhysicalSize, window::WindowAttributes};
use super::event::resize::Resized;

/// Configures a graphical application.
pub struct GraphicalApplicationOptions {
    pub tick_rate: f64,
    pub title: &'static str,
    pub width: u32,
    pub height: u32,
}

impl GraphicalApplicationOptions {
    /// Configures [`self`] with a tick rate.
    pub fn with_tick_rate(&mut self, tick_rate: f64) -> &mut Self {
        self.tick_rate = tick_rate;

        self
    }

    /// Configures [`self`] with a title.
    pub fn with_title(&mut self, title: &'static str) -> &mut Self {
        self.title = title;

        self
    }

    /// Configures [`self`] with a physical per-pixel size.
    pub fn with_size(&mut self, width: u32, height: u32) -> &mut Self {
        self.width = width;
        self.height = height;

        self
    }

    /// Creates [`WindowAttributes`] from [`self`].
    pub(crate) fn to_attr(&self) -> WindowAttributes {
        WindowAttributes::default()
            .with_title(self.title)
            .with_inner_size(PhysicalSize::new(self.width, self.height))
    }

    /// Creates a [`Resized`] event from [`self`].
    pub(crate) fn to_resized(&self) -> Resized {
        Resized::from_size(self.width, self.height)
    }
}

impl Default for GraphicalApplicationOptions {
    fn default() -> Self {
        let tick_rate = 1.;
        let title = "Application";
        let width = 1200;
        let height = 800;

        Self { tick_rate, title, width, height }
    }
}
