use serde::{Deserialize, Serialize};

use crate::adventurer::Adventurer;
use crate::tale::Tale;



/// Represents the entire blog or collection of content.
///
/// A `Tavern` contains a list of all tales (posts) and their respective
/// authors. It serves as the central structure for organizing and serializing
/// the site's content.
#[derive(Clone, PartialEq, Deserialize, Serialize)]
pub struct Tavern
{
   ///
   pub title: String,

   ///
   pub description: String,

   /// A list of all published tales (posts) in the tavern.
   pub tales: Vec<Tale>,

   /// A list of all adventurers (authors) who have contributed tales.
   pub authors: Vec<Adventurer>
}



impl Tavern
{
   #[cfg(feature = "publisher")]
   pub fn from_config_file<P>(config_file: P) -> Self
      where P: AsRef<std::path::Path>
   {
      // Read the previously written TOML file
      let toml_data =
      std::fs::read_to_string(&config_file).expect("Failed to read TOML file");

      // Deserialize it
      toml::from_str(&toml_data).expect("Failed to parse TOML")
   }
}
