use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug)]
pub struct Scene {
    /// Scene title/name
    pub title: String,
    pub visible_to_users: bool,
    /// Map for the scene, None in case of theater of the mind kinda gameplay
    pub map: Option<Map>,
    /// List of character ids, and can the party see them (maybe change that to a different thing to allow maybe 2 parties? maybe a bit field)
    pub characters: Vec<(usize, Party)>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Map {
    /// Image source for the background of the map
    pub background: String,
    // Cell size of the map grid
    pub grid_cell_size: f32,
    // Grid offset from top left, [x, y]
    pub grid_offset: [f32; 2],
    /// Tokens in the current map (should be of characters), maps from token_id to its info
    pub tokens: HashMap<usize, TokenInfo>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct TokenInfo {
    /// Which character the token refers to
    pub character: String,
    /// Token image source, as path relative to the data directory
    pub img_source: String,
    // x, y are floats to allow 'free movement'
    /// X position, in grid slots units (integers are grid aligned)
    pub x: f32,
    /// Y position, in grid slots units (integers are grid aligned)
    pub y: f32,
}

// for now this is defined so i could easily modify this later if needed (and only change initializations)
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct Party(pub bool);
impl Party {
    pub fn can_see(&self, other: Party) -> bool {
        !self.0 || other.0
    }
}
