/*
    Hurry Curry! - a game about cooking
    Copyright (C) 2026 Hurry Curry! Contributors

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, version 3 of the License only.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

*/

use crate::{ItemIndex, Message};
use glam::Vec2;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Book {
    pub pages: Vec<BookPage>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "page_type")]
pub enum BookPage {
    Cover,
    Contents {
        title: Message,
        table: Vec<(Message, usize)>,
    },
    Text {
        title: Message,
        paragraphs: Vec<Message>,
    },
    Recipe {
        title: Message,
        description: Message,
        diagram: Diagram,
        points: Vec<(ItemIndex, i64)>,
    },
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Diagram {
    pub nodes: Vec<DiagramNode>,
    pub edges: Vec<DiagramEdge>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiagramNode {
    pub position: Vec2,
    pub label: Message,
    pub style: NodeStyle,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum NodeStyle {
    IntermediateProduct,
    FinalProduct,
    ProcessActive,
    ProcessPassive,
    ProcessInstant,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiagramEdge {
    pub src: usize,
    pub dst: usize,
    pub label: Option<Message>,
}

impl NodeStyle {
    pub fn is_procuct(&self) -> bool {
        matches!(
            self,
            NodeStyle::IntermediateProduct | NodeStyle::FinalProduct
        )
    }
}
