use itertools::Itertools;

use super::{Game, enemy::Enemy, materials::MaterialDrops};

#[derive(Debug, PartialEq, Eq)]
pub struct Drops {
	pub game: Game,
	pub drops: Vec<MaterialDrops>,
	pub material_kinds: Vec<String>,

	filter_max_len: usize,
}

impl Drops {
	pub fn new(game: Game, enemies: Vec<Enemy>) -> Self {
		let drops = MaterialDrops::new(enemies);

		let material_kinds = drops
			.iter()
			.map(|d| d.category.get_category(&game))
			.dedup()
			.collect::<Vec<_>>();

		let mut filter_max_len: usize = 0;
		for kind in &material_kinds {
			if kind.len() > filter_max_len {
				filter_max_len = kind.len();
			}
		}
		filter_max_len *= 10;
		filter_max_len += 60;

		Self {
			game,
			drops,
			material_kinds,

			filter_max_len,
		}
	}

	pub fn get_filter_len(&self) -> usize {
		self.filter_max_len
	}
}
