@startuml

actor User 
participant UserAgent
participant DatabaseManager
participant TCPNetworkManager
participant BroadcastNetworkManager
database IdManager

/' To do : etablissement de connexion 
+ corriger parametre des fonctions '/




group Connexion 
    User -> UserAgent : connexion()

    alt PremiereConnexion
        UserAgent -> BroadcastNetworkManager --++ #lightgrey : getServerAddress()
        BroadcastNetworkManager -> IdManager --++ #lightgrey : getServerAddress()
        IdManager -> BroadcastNetworkManager --++ #lightgrey : ServerAddress
        BroadcastNetworkManager -> UserAgent --++ #lightgrey : ServerAddress
        UserAgent -> TCPNetworkManager --++ #lightgrey : getNextId()
        TCPNetworkManager -> IdManager --++ #lightgrey : getNextId()
        IdManager -> TCPNetworkManager --++ #lightgrey : sendId()
        TCPNetworkManager -> UserAgent -- #lightgrey : sendId()

    else DejaConnecte
        UserAgent -> UserAgent : getSelfId()
    end
    loop PseudoLibre
        UserAgent -> User --++ #lightgrey  : saisirPseudo()
        User -> UserAgent --++ #lightgrey  : envoyerPseudo(Pseudo)
        UserAgent -> BroadcastNetworkManager --++ #lightgrey : sendInformation(port, ip, id, pseudo)
        alt 
            BroadcastNetworkManager -> UserAgent --++ #lightgrey: pseudoDejaPris()
            UserAgent -> UserAgent -- : PseudoLibre = False 
        else    
            BroadcastNetworkManager -> UserAgent --++ #lightgrey : sendInformation(port, ip, id, pseudo)
            UserAgent -> UserAgent -- : PseudoLibre = True
        end
    end
 
   
    UserAgent -> DatabaseManager -- #lightgrey : storeInformations()
    UserAgent --> User -- : ok()
            
end

group DeconnexionUser
    User -> UserAgent --++ #lightgrey : deconnexion()
    UserAgent -> BroadcastNetworkManager -- : deconnexion()
end

group ChangerPseudo
    User -> UserAgent --++ #lightgrey : changerPseudo()
    loop PseudoLibre
        UserAgent -> User --++ #lightgrey  : saisirPseudo()
        User -> UserAgent --++ #lightgrey  : envoyerPseudo(Pseudo)
        UserAgent -> BroadcastNetworkManager --++ #lightgrey : sendInformation(port, ip, id, pseudo)
        alt 
            BroadcastNetworkManager -> UserAgent --++ #lightgrey: pseudoDejaPris()
            UserAgent -> UserAgent -- : PseudoLibre = False 
        else    
            BroadcastNetworkManager -> UserAgent --++ #lightgrey : sendInformation(port, ip, id, pseudo)
            UserAgent -> UserAgent -- : PseudoLibre = True
        end
    end
end

@enduml