package org.academiadecodigo.enuminatti.hibernatebootstrap;

import org.academiadecodigo.enuminatti.hibernatebootstrap.models.Address;
import org.academiadecodigo.enuminatti.hibernatebootstrap.models.User;
import org.academiadecodigo.enuminatti.hibernatebootstrap.services.UserService;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class Main {
    public static void main(String[] args) {

        UserService userService = new UserService();

        User newUser = new User("Jorge", "jorge@academiadecodigo.org");

        User addedUser = userService.save(newUser);
        System.out.println(addedUser.getName());

        addedUser.setEmail("cenas@coiso");
        addedUser.setAddress(new Address("Rua das Rosas", "Covilhã", "4500"));
        User editedUser = userService.edit(addedUser);
        System.out.println(editedUser.getEmail());

        User fetchedUser = userService.get(addedUser.getId());

        fetchedUser.getAddress().setStreet("Rua dos Casais");

        userService.edit(fetchedUser);

        System.out.println(userService.get(fetchedUser.getId()).getAddress().getCity());

        userService.close();

    }
}
