use std::cell::RefCell;
use std::rc::Rc;
// use std::borrow::BorrowMut;

struct Vertex {
    name: String,
    edges: RefCell<Vec<Vertex>>
}

struct Graph {
    vertices: Vec<RefCell<Vertex>>
}

impl Graph {
    fn new() -> Self{
        return Graph { vertices: vec![] };
    }

    fn add_node(&mut self, name: String) {
        self.vertices.push(Vertex { name: name, edges: RefCell::new(vec![]) }.into() );
    }

    fn vertices_count(&self) -> usize {
        return self.vertices.len();
    }

    
    fn connect(&mut self, i: usize, j: usize) {
        // let nodej = Rc::clone(&self.vertices[j]);
        // let nodei = Rc::clone(&self.vertices[i]);
        // nodei.into_inner();
        //nodei.edges.push(nodej);
        // .unwrap().push(self.vertices[j]);
        // Rc::into_inner(nodei).unwrap().edges.push(nodej);
        // self.vertices[i].get.push(self.vertices[j]);
        // let mut edges_new = self.vertices[i].edges.get_mut();
        // let inner = self.vertices[j].take();
        // self.vertices[i].get_mut().edges.borrow_mut().push(inner);
        let list = self.vertices[i].get_mut().edges.clone();
        self.vertices[i].get_mut().edges.replace(vec![]);
    }
    
}

fn main() {
    let mut g = Graph::new();
    g.add_node(String::from("Vertice #1"));
    g.add_node(String::from("Vertice #2"));
    g.add_node(String::from("Vertice #3"));

    g.connect(0, 1);
    g.connect(1, 2);

    println!("Done, Vertices count: {}.", g.vertices_count());
}
