#[derive(PartialEq)]
enum Category{
    Cpu,
    Gpu,
    Psu,
    Case,
    Ram,
    Storage,
    Generic
}

impl Category{
    fn get_string_category(&self) -> &str 
    {
        match self{
           Category::Cpu => return "cpu",
           Category::Gpu => return "gpu",
           Category::Psu => return "psu",
           Category::Case => return "case",
           Category::Ram => return "ram",
           Category::Storage => return "storage",
           Category::Generic=> return "unknown",
        }
    }
    fn total_price(products:&[Product], category:Category) -> f64
    {
        let mut total_price:f64 = 0.0;
       for item in products{
           if item.category == category{
               total_price+=item.price;
           }
       }
        total_price
    }
}

struct Product{
    name:String,
    price:f64,
    category:Category
}

impl Product{
    fn print_info(&self)
    {
        println!("Product: {}\n\tPrice: {}\n\tCategory{}", self.name, self.price, self.category.get_string_category());
    }
}


fn main()
{
    let products = vec![
        Product {
            name: String::from("CPU"),
            price: 100.0,
            category: Category::Cpu,
        },
        Product {
            name: String::from("GPU"),
            price: 200.0,
            category: Category::Gpu,
        },
    ];
    let cpu_price = Category::total_price(&products, Category::Cpu);
    println!("Total price for CPU: {}", cpu_price);

    let gpu_price = Category::total_price(&products, Category::Gpu);
    println!("Total price for GPU: {}", gpu_price);
}


