use crate::core::shape::CreateShape;
use crate::core::texture::FloatTexture;
use crate::{Arena, FileLoc, ParameterDictionary};
use anyhow::Result;
use shared::core::shape::Shape;
use shared::shapes::DiskShape;
use shared::{Ptr, Transform};
use std::collections::HashMap;
use std::sync::Arc;

impl CreateShape for DiskShape {
    fn create(
        render_from_object: Transform,
        object_from_render: Transform,
        reverse_orientation: bool,
        parameters: ParameterDictionary,
        _float_textures: &HashMap<String, Arc<FloatTexture>>,
        _loc: FileLoc,
        arena: &Arena,
    ) -> Result<Vec<Ptr<Shape>>> {
        let height = parameters.get_one_float("height", 0.)?;
        let radius = parameters.get_one_float("radius", 1.)?;
        let inner_radius = parameters.get_one_float("innerradius", 0.)?;
        let phi_max = parameters.get_one_float("phimax", 360.)?;
        let shape = DiskShape::new(
            radius,
            inner_radius,
            height,
            phi_max,
            render_from_object,
            object_from_render,
            reverse_orientation,
        );

        Ok(vec![arena.alloc(Shape::Disk(shape))])
    }
}
