use bevy::prelude::*;
use serde::{Deserialize, Serialize};

use super::*;

#[derive(Clone, Default, Debug, Hash, Eq, PartialEq, Serialize, Deserialize, Reflect)]
pub struct SiteDef {
    pub id: String,
    pub min_size: i32,
    pub max_size: i32,
    pub is_underground: bool,
    pub is_natural: bool,
}

impl SiteDef {
    pub const CATEGORY: TopLevelTag = TopLevelTag::Site;

    pub fn parse(header: Tag, tags: &[Tag]) -> Result<Self, ParseError> {
        let mut result = Self {
            id: header.parse_value::<String>().unwrap(),
            ..Default::default()
        };
        for tag in tags {
            match tag.name.as_str() {
                "SIZE" => (result.min_size, result.max_size) = tag.parse_value().unwrap(),
                "NATURAL" => result.is_natural = true,
                "UNDERGROUND" => result.is_underground = true,
                _ => {
                    // warn!("Unknown tag '{}' in SITE defs", tag.name);
                    return Err(ParseError::UnknownTag {
                        tag: tag.name.clone(),
                        id: Some(result.id),
                        category: Some(Self::CATEGORY),
                    });
                }
            }
        }
        Ok(result)
    }
}
