package fr.marouse;

import fr.marouse.entity.Agent;
import fr.marouse.entity.Client;
import fr.marouse.entity.Compte;
import fr.marouse.repository.ClientRepository;
import fr.marouse.repository.jpa.ClientRepositoryJPA;
import fr.marouse.service.BanqueService;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

import java.sql.Date;
import java.util.List;

public class Main {

    public static void main(String[] args) {

        EntityManagerFactory emf =
                Persistence.createEntityManagerFactory("banquePU");
        EntityManager em = emf.createEntityManager();

        ClientRepository clientRepository =
                new ClientRepositoryJPA(em);
        BanqueService banqueService =
                new BanqueService(clientRepository);

        Agent agent = new Agent("Martin", "Paul", 2500, false);

        Client client = new Client(
                "Dupont",
                "Jean",
                "Adresse",
                new Date(System.currentTimeMillis()),
                agent,
                30
        );

        banqueService.creerClient(client);

        List<Compte> comptes =
                banqueService.getComptesClient(client.getNumClient());

        comptes.forEach(c ->
                System.out.println(
                        "Compte " + c.getNumCompte() +
                        " | Solde = " + c.getSolde()
                )
        );

        em.close();
        emf.close();
    }
}
