use shared::Float;
use shared::core::geometry::{Bounds2i, Point2i};
use shared::spectra::RGBColorSpace;
use shared::utils::math::SquareMatrix;
use std::collections::HashMap;

#[derive(Debug, Clone, Default)]
pub struct ImageChannelDesc {
    pub offset: Vec<usize>,
}

impl ImageChannelDesc {
    pub fn new(offset: &[usize]) -> Self {
        Self {
            offset: offset.into(),
        }
    }

    pub fn size(&self) -> usize {
        self.offset.len()
    }

    pub fn is_empty(&self) -> bool {
        self.offset.is_empty()
    }
    pub fn is_identity(&self) -> bool {
        for i in 0..self.size() {
            if self.offset[i] != i {
                return false;
            }
        }
        true
    }
}

#[derive(Debug, Default, Clone)]
pub struct ImageMetadata {
    pub render_time_seconds: Option<Float>,
    pub camera_from_world: Option<SquareMatrix<Float, 4>>,
    pub ndc_from_world: Option<SquareMatrix<Float, 4>>,
    pub pixel_bounds: Option<Bounds2i>,
    pub full_resolution: Option<Point2i>,
    pub samples_per_pixel: Option<i32>,
    pub mse: Option<Float>,
    pub colorspace: Option<RGBColorSpace>,
    pub strings: HashMap<String, String>,
    pub string_vectors: HashMap<String, Vec<String>>,
}

impl ImageMetadata {
    pub fn get_colorspace(&self) -> Option<RGBColorSpace> {
        self.colorspace
    }
}
